Monday, March 9, 2009

Subtyping  

0 comments

you can assign an Integer to an Object, since Object is one of Integer's supertypes: 
  Object someObject = new Object();
  Integer someInteger = new Integer(10);
  someObject = someInteger; // OK
In object-oriented terminology, this is called an "is a" relationship. Since an Integer is a kind of Object, the assignment is allowed. But Integer is also a kind of Number, so the following code is valid as well: 
  public void someMethod(Number n){
  // method body omitted 
  }

  someMethod(new Integer(10)); // OK
  someMethod(new Double(10.1)); // OK

What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



0 comments: to “ Subtyping

Extension Factory Builder