Parent reference, child object: what runs?
QuizMediumJava onlyAsked in: Accenture, Capgemini, Cognizant, Infosys, TCS, Wipro
What does the last line print?
class Animal {
String name = "animal";
static String kind() { return "Animal.kind"; }
String sound() { return "..."; }
}
class Dog extends Animal {
String name = "dog";
static String kind() { return "Dog.kind"; }
String sound() { return "woof"; }
}
// in main:
Animal x = new Dog();
System.out.println(x.name + " " + x.sound() + " " + x.kind());animal woof Animal.kinddog woof Dog.kindanimal ... Animal.kinddog woof Animal.kind
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.