Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 5 Consider the following Java code. class MyTest { public static void main(String[] args) { SubClass s = new SubClass(1); } } class SuperClass{

QUESTION 5

  1. Consider the following Java code. class MyTest { public static void main(String[] args) { SubClass s = new SubClass(1); } } class SuperClass{ private int superClassField; public SuperClass(int f){ superClassField = f + 1; System.out.println("SuperClass constructor, field = " + superClassField); } } class SubClass extends SuperClass{ public SubClass(int f){ super(f); System.out.println("SubClass constructor, field = " + f); } } What output will be produced?

A.

SuperClass constructor, field = 2

SubClass constructor, field = 1

B.

SuperClass constructor, field = 1

SubClass constructor, field = 1

C.

SuperClass constructor, field = 2

SubClass constructor, field = 2

D.

SuperClass constructor, field = 1

SubClass constructor, field = 2

QUESTION 6

  1. Consider the following Java code. class MyTest { public static void main(String[] args) { print(new Object()); print(new SuperClass()); print(new SubClass()); print(new SubSubClass()); } public static void print(SubClass s){ System.out.println(s.toString()); } } class SuperClass{ public String toString(){ return "Superclass"; } } class SubClass extends SuperClass{ public String toString(){ return "Subclass"; } } class SubSubClass extends SubClass{ } Which (if any) lines of code will produce a compile time error (try to avoid copying and pasting the code!).

A.

print(new SuperClass()); only.

B.

print(new Object()); and print(new SuperClass());

C.

print(new Object()); only.

D.

The code will not produce a compile time error.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago