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();
More Related Contents:
- How to cast an Object to an int
- Casting an array of Objects into an array of my intended class
- Java rules for casting
- How do i get an object from another class in java
- get specific data filed from returned object in java
- How do I correctly implement this code segment without getting a logic error? [closed]
- What is the difference between a variable, object, and reference? [duplicate]
- Can we instantiate an abstract class?
- Is there a way to instantiate a class by name in Java?
- What is the difference between “Class.forName()” and “Class.forName().newInstance()”?
- casting Object array to Integer array error
- java: How can I do dynamic casting of a variable from one type to another?
- How can I get the memory location of a object in java?
- Cast Int to enum in Java
- make arrayList.toArray() return more specific types
- How are integers cast to bytes in Java?
- Postgres data type cast
- Explicit type casting example in Java
- Can’t cast to to unspecific nested type with generics
- Cannot convert from List to List
- Difference Between Object Type and Reference Type
- What does the ‘new’ keyword actually do in Java, and should I avoid creating new objects?
- Differences in auto-unboxing between Java 6 vs Java 7
- Steps in the memory allocation process for Java objects
- Java Casting Interface to Class
- Java: For-Each loop and references [duplicate]
- Classes that don’t inherit Object class
- Java: Long result = -1: cannot convert from int to long
- How many Java objects are generated by this – new String(“abcd”)
- How do I convert from int to Long in Java?