View RSS Feed

My Java Tips


Rate this Entry
by , 11-03-2011 at 01:17 PM (955 Views)
Subtyping is very important in Java. One type is said to be subtype of other if they are related by an extend or implements clause.

For instance:

Integer is a subtype of Number
Double is a subtype of Number
ArrayList is a subtype of List
List is a subtype of Collection
Collection is a subtype of Iterable

Subtyping principle says that a variable of type A can be assigned a value of any subtype of A and methods can be invoked as well.
Review the code below:

Java Code:
ArrayList myArrayList = new ArrayList();

String []strArray= new String[10];

for(int i=0;i<10;i++){
   strArray[i] = "Element" + i;


ArrayList myArrayList1 = myArrayList;

Submit "Subtyping" to Facebook Submit "Subtyping" to Digg Submit "Subtyping" to Submit "Subtyping" to StumbleUpon Submit "Subtyping" to Google

Tags: None Add / Edit Tags
Java SE