What is the output of the following code? A. public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } B. class Student extends Person { private String getInfo() { return "Student"; } } C. class Person { private String getInfo() { return "Person"; } D. public void printPerson() { System.out.println(getInfo()); } }

Respuesta :

ijeggs

Answer:

Person

Person

Explanation:

The code snippet has three class. These are

1. Test (Contains the main Method)

2. Person

3. Student (which inherits the person class)

The class Person has this method

 public void printPerson() {

       System.out.println(getInfo())}

That prints a person information.

In the Test class when these statements executes

       new Person().printPerson();

       new Student().printPerson();

The output is the same since the method printPerson() is inherited by the Student class and there is no Overide