Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 7 Consider the following Java code. class MyTest { public static void main(String[] args) { SubClass s = new SubSubClass(); System.out.println(s.toString()); } } class

QUESTION 7

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

A.

SubSubClass.

B.

The code will not compile.

C.

SuperClass.

D.

SubClass.

QUESTION 8

  1. Which of the following statements are correct?
    1. A method can be overloaded in the same class.
    2. A method can be overridden in the same class.
    3. If a method overloads another method, these two methods must have the same signature.
    4. If a method overrides another method, these two methods must have the same signature.

A.

1 and 4 only.

B.

2 and 3 only.

C.

1 and 3 only.

D.

2 and 4 only.

QUESTION 9

  1. Consider the following Java code. class MyTest { public static void main(String[] args) { SubClass s = new SubClass(); s.superClassField = 20; System.out.println(s.toString()); } } class SuperClass{ int superClassField = 10; public String toString(){ return "Superclass field is " + superClassField; } } class SubClass extends SuperClass{ public String toString(){ return "Subclass field is " + super.superClassField; } } Which of the following statements are correct?
    1. Given the object s, any other class could change the value of superClassField.
    2. Making superClassField to be private would improve encapsulation, and the code would compile.
    3. Making superClassField to be private would improve encapsulation, but the code will not compile.
    4. Making superClassField to be protected would improve encapsulation, and the code would compile.
    5. Without any modification the code output is Subclass field is 20.
    6. Without any modification the code will not compile.

1, 3, 4, and 5 only.

3, 4, and 5 only.

1, 2, and 5 only.

1, 3, 4 and 6 only.

10 points

QUESTION 10

  1. Which of the following would be a correct use of inheritance?
    1. Beverage extends Martini.
    2. Guitar extends Instrument.
    3. Employee extends SmartPerson
    4. Oven extends Kitchen
    5. Beatles extend Band

A.

2, 4, and 5 only.

B.

4 and 5 only.

C.

1, 3, and 5 only.

D.

2 and 5 only.

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions