Question: Which one is correct about the following block of code in java: class Animal { public static void main ( String args [ ] )

Which one is correct about the following block of code in java:
class Animal {
public static void main(String args[]){
Animal animal = new Animal();
Dog dog = new Dog();
animal.print();
dog.print();
}
void print(){
System.out.println("Superclass Animal");
}
}
public class Dog extends Animal {
void print(){System.out.println("Subclass Dog");
}
}
Question 9 options:
Dog is the superclass and Aminal is the subclass
The print method in the Animal class overloads the print method in the Dog class
A superclass variable can only shadow a subclass variable
The print method in the Dog class overrides the print method in the Animal class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!