Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 9 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());

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.

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago

Question

1. Explain why evaluation is important.

Answered: 1 week ago