Quiz Guidelines


Multiple Choice Question


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


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


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 ______();
}   }

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


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


Which of the following access control keywords can be used to enable all the subclasses to access a method defined in the base class?

Select 2 options 

A. public 
B. private 
C. protected 
D. No keyword is needed.