ClassName a = new ClassName1();
What does ClassName and ClassName1 mean? I thought that ClassName had to equal ClassName1.
ClassName a = new ClassName1();
What does ClassName and ClassName1 mean? I thought that ClassName had to equal ClassName1.
If
public class ClassName1 extends/implements ClassName
than it is perfectly valid.
This is how polimorphism works - you can treat given instance as it would be a solely instance of any of its superclasses or interfaces it implements.
ClassName
is the type of the variable a
, which means for your problem, that a
can represents an object of the type ClassName
(and any other subclass of it).
So, the sentence ClassName a = new ClassName1()
only make sense and is right if the ClassName1
is a subclass of ClassName
.