Question: 1. Which of the following statements about inheritance in Java are correct? A subclass is a subset of its superclass. x A subclass includes more

1. Which of the following statements about inheritance in Java are correct?

  1. A subclass is a subset of its superclass. x
  2. A subclass includes more functionality and stores more information than its superclass.
  3. The statement 'class A extends B' means that A is a subclass of B.
  4. The statement 'class A extends B' means that B is a subclass of A.

A.

1 and 3 only.

B.

2 and 4 only.

C.

2 and 3 only.

D.

1 and 4 only.

QUESTION 2

  1. Consider the following Java code. public class myTest{ public static void main (String[] args){ SubClass s = new SubClass(); s.print(); } } class SuperClass{ int myID = 1; public void print(){ System.out.println(myID); } } class SubClass extends SuperClass{ int myID = 2; } What output will this code produce?

A.

The code will not compile.

B.

2.

C.

1.

D.

0.

QUESTION 3

  1. Consider the following Java code. public class myTest{ public static void main (String[] args){ SubClass s = new SubClass(); s.print(); } } class SuperClass{ int myID = 1; } class SubClass extends SuperClass{ int myID = 2; public void print(){ System.out.println(super.myID); } } What output will this code produce?

A.

2.

B.

The code will not compile.

C.

0.

D.

1.

QUESTION 4

  1. Consider the following Java code. class MyTest { public static void main(String[] args) { SubClass s = new SubClass(); } } class SuperClass{ public SuperClass(){ System.out.println("SuperClass constructor"); } } class SubClass extends SuperClass{ public SubClass(){ System.out.println("SubClass constructor"); } } What output will be produced when the code is run?

A.

SubClass constructor

SuperClass constructor

B.

SuperClass constructor

SubClass constructor

C.

SubClass constructor

D.

SuperClass constructor.

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!