Let's say we have some class structure:

     public interface IA { public void doA(); }
     public class A implements IA { public void doA(){ System.out.println("A class doA");}
     public class B extends A { public void doA(){ System.out.println("B class doA"); }

And now in a main I state this:

     //in a main
     IA ia = new B();

Am I correct in stating that the the runtime object of ia is a B class and it has inherited all the super classes methods and attributes?

The printout from within the imaginary main is B class doA as the method doA in B will hide the same methods in its super classes?

  • 1
    What's the difference between override and new? Whoops. Wrong language. Java documentation
    – Nathan
    Commented Mar 5, 2014 at 12:40
  • possible duplicate of What's the difference between overloading a method and overriding it in Java?
    – gnat
    Commented Mar 5, 2014 at 12:59
  • As for your last question: have you tried running the code? This is very easy to test...
    – Andres F.
    Commented Mar 5, 2014 at 13:02
  • 2
    The way I prefer to think of inheritance hierarchies including interfaces is by understanding that "subclass" and "subtype" are different qualities. B is a subclass of A, but a subtype of A and IA. Subtyping relationships are important for defining what variable type you can assign some entity to, and subclass relationships are important for defining what behaviour some entity has.
    – Phoshi
    Commented Mar 5, 2014 at 13:08
  • C# or Java, still same basic idea ;). @AndresF. I have compiled the code and it does what i expected it to do, Biggest issue for me is how to define why so i can learn it. I think i have got a clearer view of this type of override & overload. Found another link that is not that bad ;) Java docs Thnx everyone! Commented Mar 5, 2014 at 13:44

1 Answer 1


Yes, you are correct.

  1. ia is of class B
  2. ia is also of class A since B inherits A.
  3. B overrrides A's doA() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.