When you reference an object using its interface, for example
I ref = new B();
then you have access only to the interface and methods of the object class . You do not have the class methods visible until you add the object to your class.
If you want to access the method declared in class A , you can do one of the following:
I ref = new B(); ((A)ref).method()
or
A ref = new B(); ref.method();
or
B ref = new B(); ref.method();
source share