Casting

Casting

Integer Hierarchy

  1. long
  2. int
  3. short
  4. char
  5. byte

Floating Hierarchy 

  1. double
  2. float
According to the above sequence the data types that are in the highest point have the highest power than lowers.

Upcasting

We can understand upcasting simply as giving the subclass object to the super class variable.
In upcasting we cannot access higher types by lower types.
But lower types can be accessed by higher types.

Downcasting

Converting the sub class object added to the super class variable back into sub class variable.
This is simply giving the super class variable to the sub class variable.
For this,sub class object is used as parameter.





Comments

Popular posts from this blog

Variable and Method types in JAVA

Polymorphism