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

What is wrong with the following Java code? final class First { private int a; i

ID: 3924743 • Letter: W

Question

What is wrong with the following Java code?

final class First
{
     private int a;
      int b;
      First()
      {
            a = 10;
           b = 20;
      }
}

class Second extends First
{
       public void method()
       {
             System.out.println( a + b);
      }
}

SELECT ALLL POSSIBLE RESPONSES

Select one or more:

a. Because the variable a is private, no class other than First can access it.

b. Nothing is wrong with the code, it will compile.

c. The class Second cannot extend First, beacuse the class First is a terminal class.

d. final is not a valid keyword for a class, it is only used with constants.

e. You cannot call the println() method without passing a String to it.

Explanation / Answer

Answer:

a. Because the variable a is private, no class other than First can access it.

c. The class Second cannot extend First, beacuse the class First is a terminal class.

These two are the correct answers.

Final class can not be inherited. So once we apply final key word on class that is a final class and can not be inherited.

"a" variable is a private variable and the scope of that variable is with in that same class and can not be visiblt to other classes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote