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

1) Look at the following code. Which line in ClassA has an error: Line 1 public

ID: 3834507 • Letter: 1

Question

1)

Look at the following code. Which line in ClassA has an error:

Line 1   public interface MyInterface

Line 2   {

Line 3     public static final int FIELDA = 55;

Line 4     public int methodA(double);

Line 5   }

Line 6 public class ClassA implements MyInterface

Line 7   {

Line 8     FIELDA = 60;

Line 9     public int methodA(double) { }

Line 10 }

2)

Look at the following code.

Line 1   public class ClassA

Line 2   {

Line 3     public ClassA() {}

Line 4     public void method1(int a){}

Line 5   }

Line 6   public class ClassB extends ClassA

Line 7   {

Line 8     public ClassB(){}

Line 9     public void method1(){}

Line 10   }

Line 11   public class ClassC extends ClassB

Line 12   {

Line 13     public ClassC(){}

Line 14     public void method1(){}

Line 15   }

Which method will be executed as a result of the following statements?

ClassB item1 = new ClassA();

item1.method1();

3

Look at the following code and determine what the call to super will do.

public class ClassB extends ClassA

{

public ClassB()

{

    super(10);

}

}

_

A)

The method super will have to be defined before we can say what will happen

B)

This cannot be determined form the code

C)

It will call the constructor of ClassA that receives an integer as an argument

D)


It will call the method super and pass the value 10 to it as an argument

Explanation / Answer

1)
The line Line 8     FIELDA = 60;contains an error.

Explanation :
The variable FIELDA is declared as constant in MyInterface class.
The classA implmenets the MyInterface triying to modify the
constant value FIELDA .So the compiler throws an error.

2)
ClassB item1 = new ClassA();
item1.method1();

The class object item1 calling method1 which is overridden
in the class B.
The method1 of the classA will execute before the overriden
method in the classB as per class hierarchy .

3)
The correct answer is
C)It will call the constructor of ClassA that receives an integer as an argument

explantaion:
The super method calling will calls the base class constructor .
here the base class A.
The super(10) calls the base class constructor with integer argument
and pass the argument to the class A .