wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz for Module3

Total questions: 20

Worksheet time: 19mins

Name
Class
Date
1.

Suppose A is an abstract class, B is a concrete subclass of A. Both A and B have a default constructor.

Which of the following options are correct?

1. A a = new A();

2. A a= new B();

3. B b = new A();

4. B b= new B();

a)

1 and 2

b)

2 and 4

c)

3 and 4

d)

1 and 3

2.

Predict the output:

a)

a=10

b)

a=20

c)

Compilation Error at Line 3 : Constructor name should be same as that of class name.

d)

Compilation Error at

Line 7 : Method cannot be both abstract and final,

Line 13 : Cannot override the final method.

3.

Predict the output:

a)

welcome

10

20

b)

Error in Line 2 : Modifier static not allowed here.

c)

Error in Line 7: Modifier static not allowed here.

d)

Compilation Error in both Line 2 and Line 7.

4.

Which one of the below options is correct as per the given piece of code?

a)

SIMRAN

b)

Compilation error : Final variable should be initialized before starting the execution.

c)

Compilation error : Java does not allow final keyword before the constructor.

d)

Compilation error : this keyword cannot be used with final variable.

5.

Predict the output:

a)

Application Successful

b)

Application Successful

Method C

c)

Compilation Error at Line 7 : Cannot extend multiple interfaces.

d)

Compilation Error at Line 10 : Add unimplemented methods.

6.

Identify the lines that can be replaced at /*Insert code here.*/ in the given code to display 100 successfully:

1. Testable.testValue;

2. Test.Testable.testValue;

3. Test.testValue;

4. new Test().testValue;

a)

Option 1 and 2.

b)

Option 2 and 3.

c)

Option 1, 3 & 4.

d)

All the four options.

7.

Predict the output:

a)

NullPointerException

b)

9

c)

5

d)

None of the above

8.

Which one of the following statements will import all the classes from java.util package?

a)

import java.*;

b)

import *.*;

c)

import java.util.*;

d)

import java.util;

9.

Which of the following access specifiers can be used with a class so that it is visible only within the same package?

a)

public

b)

No Access Specifiers

c)

protected

d)

private

10.

Which of the below statements are true about interfaces?

Statement 1: An interface cannot be instantiated.

Statement 2: An interface cannot contain any constructors.

Statement 3: An interface cannot contain instance variables.

a)

Statement 1 ,2 & 3 are true

b)

Statement 1 & 2 are true

c)

Statement 1 & 3 are true

d)

All the statements are false

11.

Predict the output:


int arr[ ] = new int[5];

System.out.println(arr[1]);

a)

1

b)

0

c)

null

d)

Garbage Value

12.
Which of the following statement is true about Abstract classes?
a)
An Abstract class muct have atleast one abstract method.
b)
All methods of an abstract class are by default public and abstract.
c)
Abstract class can have non-abstract methods.
d)
Abstract class can be instantiated.
13.
Which of the following statement is true about Interfaces?
a)
An Interface can contain constructors.
b)
An Interface can be instantiated.
c)
An Interface can extend another Interface.
d)
An Interface is extended by a class.
14.
Which of the following statement is true regarding Function overriding in Java?
a)
Function overriding can happen only when Inheritance is done.
b)
Function Overriding can happen within the same class.
c)
Function overriding is an example of Compile time polymorphism.
d)
None of the above.
15.
Which of the following Junit annotation will make sure that the annotated method will run before each test method in the class?
a)
@Test
b)
@Before
c)
@BeforeClass
d)
None of the above.
16.
Which of the following annotation is used to mark a Test method in Junit?
a)
@JunitTest
b)
@TestMethod
c)
@Test
d)
None of the above.
17.
In which of the package are Junit annotations found?
a)
java.lang
b)
java.util
c)
java.sql
d)
None of the above.
18.
Which of the following method of the BufferedReader class is used for reading a line of text?
a)
readLine()
b)
read()
c)
readString()
d)
readInput()
19.
Which of the following is the immediate parent class for Integer, Float and Long classes?
a)
Object
b)
Number
20.
Which of the following represents the standard error stream?
a)
System.out
b)
System.in
c)
System.err
d)
System.error