Question:

Please this is the last question I am not sure about Java.?

by  |  earlier

0 LIKES UnLike

What is wrong with the following code?

public class ClassB extends ClassA

{

public ClassB()

{

int init = 10, final = 60;

super(40);

}

}

a. Nothing is wrong with the code.

b. The method super is not defined.

c. The call to the method super must be the first statement in the constructor.

d. No values may be passed to super.

Points: 2.0)

What will be the value of loc after the following code is executed?

int loc;

String str = "I love Java."

loc = str.indexOf("ov");

a. 2

b. 3

c. 4

d. 12

 Tags:

   Report

3 ANSWERS


  1. B

    B


  2. The correct answers are

    C and

    B

  3. C

    The use of the super keyword is a demand by a constructor of a subclass to perform its parent's construction steps (the parent constructor with the same method signature as the child constructor). That request must alway come before any of the (extension) processing of the child constructor.

    B

    The first index positions of the substring 'ov' are 3 and 4 (origin is 0 - so the 4th and 5th positions are indexes 3 and 4). Thus, indexOf() returns the value 3, the starting index of the first character in the substring mask.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.