Abstraction

Quiz Guidelines

 

Multiple Choice Question

QID: 
379

Consider the following interface definition:

interface Bozo{
int type = 0;
public void jump();
}
Now consider the following class:
public class Type1Bozo implements Bozo{
public Type1Bozo(){
type = 1;
}
public void jump(){
System.out.println("jumping..."+type);
}
public static void main(String[] args){
Bozo b = new Type1Bozo();
b.jump();
}
}

What will the program print when compiled and run?

Select 1 option

A. jumping...0
B. jumping...1
C. This program will not compile.
D. It will throw an exception at runtime.

Multiple Choice Question

QID: 
378

Which of these statements about interfaces are true?

Select 3 options

A. Interfaces are abstract by default.
B. An interface can have static methods.
C. All methods in an interface are abstract although you need not declare them to be so.
D. Fields of an interface may be declared as transient or volatile but not synchronized.
E. interfaces cannot be final.

Multiple Choice Question

QID: 
377

Consider the following classes in one file named A.java...

abstract class A{   
protected int m1(){ return 0; } } 
class B extends A{   int m1(){ 
return 1; } }

Which of the following statements are correct...

Select 1 option 

A. The code will not compile as you cannot have more than 1 class in 1 file. 
B. The code will not compile because class B does not override the method m1() correctly. 
C. The code will not compile as A is an abstract class. 
D. The code will not compile as A does not have any abstract method. 
E. The code will compile fine. 

Multiple Choice Question

QID: 
376

Note: This question may be considered too advanced for this exam. Given:

class MySuper{
public MySuper(int i){ }
}
abstract class MySub extends MySuper{
public MySub(int i){ super(i); }
public abstract void m1();
}
class MyTest{
public static void main(String[] args){
MySub ms = new MySub(){
public void m1() { System.out.println("In MySub.m1()"); }
};
ms.m1();
}
}

What will be the output when the above code is compiled and run?

Select 1 option

A. It will not compile.
B. It will throw an exception at run time.
C. It will print In MySub.m1()
D. It will compile and run without any exception but will not print anything.

Multiple Choice Question

QID: 
375

Which of these statements concerning interfaces are true?

Select 2 options

A. An interface may extend an interface.
B. An interface may extend a class and may implement an interface.
C. A class can implement an interface and extend a class.
D. A class can extend an interface and can implement a class.
E. An interface can only be implemented and cannot be extended.

Pages