Casting objects in Java

The Solution to Casting objects in Java is


Have a look at this sample:

public class A {
  //statements
}

public class B extends A {
  public void foo() { }
}

A a=new B();

//To execute **foo()** method.

((B)a).foo();

~ Answered on 2011-03-15 02:32:31


Most Viewed Questions: