I'm now learning java inheritance and I have a problem: if there're two classes:
public class A{
//code of class A
}
public class B extends A{
//code of class B
//code in B rewrite some methods in A
}
and, if I want to use those classes and create a 'B' object in my client program. Are there any difference between
A objectName = new B();
and
B objectName = new B();
?
Thanks.
A objectName = new B();will only allow you to access the properties and methods defined byA- this is part of polymorphismC extends Ae.g. for performance or implementation reasons, whilst making sure you code still works