Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA homework help thank you! For the next 8 questions, use the following class

ID: 3675968 • Letter: J

Question

JAVA homework help thank you!

For the next 8 questions, use the following class headers:

public class Student extends Person

public class Undergraduate extends Student

Question 9

The following is a legal assignment statement.

Person p1 = new Student();

Select one:

True

False

Question 10

The following is a legal assignment statement.

Person p2 = new Undergraduate();

Select one:

True

False

Question 11

The following is a legal assignment statement.

Student s1 = new Person();

Select one:

True

False

Question 12

The following is a legal assignment statement.

Student s2 = new Undergraduate();

Select one:

True

False

Question 13

The following is a legal assignment statement.

Undergraduate u1 = new Person();

Select one:

True

False

Question 14

The following is a legal assignment statement.

Undergraduate u2 = new Student();

Select one:

True

False

Question 15

The following is a legal assignment statement.

Object o1 = new Student();

Select one:

True

False

Question 16

The following is a legal assignment statement.

Student s3 = new Object();

Select one:

True

False

Question 17

What is printed by the following code?

public class Figure {

public void display() {

System.out.print("Figure");

}
public void display(String s) {

System.out.print("Figure" + s);

}

}
public class Rectangle extends Figure {

public void display() {

System.out.print(“Rectangle”);

}
public void display(String s) {

System.out.print("Rectangle" + s);

}

}

public class Box extends Rectangle {

public void display( ) {

System.out.print("Box");

}
public void display(String s) {

System.out.print("Box" + s);

}

}
public class DoIt {

public static void main(String[ ] args) {

Figure f = new Figure();
f.display();
Figure f2 = new Rectangle();
f2.display("One");
Figure f3 = new Box();
f3.display("Two");

}

}

Answer:

Question 18

In the question above, what is the declared type of f2?

Select one:

Figure

Rectangle

Box

None of the above

Question 19

In the question above, what is the actual type of f2?

Select one:

Figure

Rectangle

Box

None of the above

Question 20

What is printed by the following code?

public class Figure {

public void display() {

System.out.print("Figure");

}

}
public class Rectangle extends Figure {

public void display() {

super.display();
System.out.print(“Rectangle”);

}

}

public class Box extends Rectangle {

public void display() {

System.out.print("Box");

}

}
public class DoIt {

public static void main(String[ ] args) {

Figure f = new Rectangle();
f.display();
Figure f2 = new Box();
f2.display();

}

}

Answer:

Question 21

What is printed by the following code?

public class Figure {

public void display() {

System.out.print("Figure");

}

}
public class Rectangle extends Figure {

public void display() {

System.out.print(“Rectangle”);

}

}

public class Box extends Rectangle {

public void display( ) {

System.out.print("Box");

}

}
public class DoIt {

public static void main(String[ ] args) {

Figure f = new Figure();
f.display();
Figure f2 = new Rectangle();
f2.display();
Figure f3 = new Box();
f3.display();

}

}

Answer:

Explanation / Answer

Question 9

Answer is True.

A base class object can be created by instantiating any of the child class

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 10

Answer is True.

A base class object can be created by instantiating any of the child class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 11

Answer is False.

A child class object cannot be created by instantiating base class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 12

Answer is True.

A base class object can be created by instantiating any of the child class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 13

Answer is False.

A child class object cannot be created by instantiating base class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 14

Answer is False.

A child class object cannot be created by instantiating base class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 15

Answer is True.

A generic object can be created by instantiating any of the class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 16

Answer is False.

A class object cannot be created by instantiating Generic object class

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 17

Output of the given program: FigureRectangleOneBoxTwo

(i) Object f is created by instantiating class Figure. Statement "f.display()" executes display method in class Figure
(ii) Object f2 is created by instantiating class Rectangle. Statement "f2.display("One")" executes display method in class Rectangle
(iii) Object f3 is created by instantiating class Box. Statement "f3.display("Two")" executes display method in class Box

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 18

Answer is Figure

Declared type is the one used while first declaring a variable.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 19

Answer is Rectangle

Actual type is the one that the variable is actually assigned.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 20

Output of the given program: FigureRectangleBox

(i) Object f is created by instantiating class Rectangle. Statement "f.display()" executes display method in class Rectangle which in turn class display method of Figure class.
(ii) Object f2 is created by instantiating class Box. Statement "f2.display("Two")" executes display method in class Box

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question 21

Output of the given program: FigureRectangleBox

(i) Object f is created by instantiating class Figure. Statement "f.display("Figure")" executes display method in class Figure
(ii) Object f2 is created by instantiating class Rectangle. Statement "f2.display("Rectangle")" executes display method in class Rectangle
(iii) Object f3 is created by instantiating class Box. Statement "f3.display("Box")" executes display method in class Box