Answer the question
In order to leave comments, you need to log in
Subclass fields under polymorphism?
Why are subclass variables visible in polymorphism that are not in the superclass?
class Greeting{
protected void sayHello(){
System.out.println("hello");
}
}
class GreetingByName extends Greeting{
String name = "Vasya";
@Override
protected void sayHello() {
System.out.println("hello " + name);
}
}
Greeting greeting = new GreetingByName();
greeting.sayHello();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question