JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
497

Consider the following classes...

class Teacher{
void teach(String student){                    /* lots of code */
}
}class Prof extends Teacher{             //1
}

Which of the following methods can be inserted at line //1 ?

Select 4 options

A. public void teach() throws Exception
B. private void teach(int i) throws Exception
C. protected void teach(String s)
D. public final void teach(String s)
E. public abstract void teach(String s)

Multiple Choice Question

QID: 
498

What should be placed in the two blanks so that the following code will compile without errors:

class XXX{
public void m() throws Exception{
throw new Exception();
}   }class YYY extends XXX{
public void m() {
}   }public class TestClass {
public static void main(String[] args) {
______ obj = new ______();
obj.m();
}   }

Select 1 option

A. XXX and YYY
B. XXX and XXX
C. YYY and YYY
D. YYY and XXX
E. Nothing will make the code compile.

Multiple Choice Question

QID: 
499

Given the following code, which of these constructors can be added to class B without causing a compile time error?

class A{
int i;
public A(int x) { this.i = x; }
}class B extends A{
int j;
public B(int x, int y) { super(x); this.j = y; }
}

Select 2 options

A. B( ) { }
B. B(int y ) { j = y; }
C. B(int y ) { super(y*2 ); j = y; }
D. B(int y ) { i = y; j = y*2; }
E. B(int z ) { this(z, z); }

Multiple Choice Question

QID: 
500

Given that OurClass is a MyClass and OurClass has a YourClass object.

Which of the following options are correct?
(Assume and OurClass, MyClass, and YourClass are valid java classes.)

Select 2 options

A. MyClass contains a reference to OurClass
B. OurClass contains a reference to MyClass 
C. MyClass contains a reference to YourClass
D. OurClass contains a reference to YourClass
E. OurClass inherits from MyClass

Multiple Choice Question

QID: 
501

Consider the following interface definition:

public interface ConstTest{
 public int A = 1; //1
 int B = 1;          //2
 static int C = 1;  //3
 final int D = 1;   //4
 public static int E = 1; //5
 public final int F = 1;  //6
 static final int G = 1;    //7
 public static final int H = 1; //8
}

Which line(s) will cause a compilation error?

Select 1 option

A. 1
B. 2 
C. 3 
D. 4 
E. 5 
F. 6
G. 7
H. 8 
I. None of them will cause any error.

Pages