NEW
Font size
WorksheetsJAVA FINAL QUIZ FOR ASSESSMENT
Total questions: 15
Worksheet time: 8mins
Predict the output of the following code.
abstract class A
{
public void disp()
{
System.out.println("Concrete method of parent class");
}
abstract public void disp2();
}
class B extends A
{
public void disp2()
{
System.out.println("Overriding abstract method");
}
public static void main(String args[])
{
B obj = new B();
obj.disp();
}
}
Overriding abstract method
Concrete method of parent class
Runtime error: non abstract method of parent cannot be invoked using child object
Compilation error: abstract class cannot have non abstract methods
Which of the following class creation prevents creating a child class of the Example class?
class Example {}
abstract public class Example {}
public final class Example {}
Which of the following is/are true for classes and interfaces?
"Account extends SavingsAccount" is correct if and only if "Account is a class" and "SavingsAccount is an interface"
"Account extends SavingsAccount" is correct if and only if "Account is an interface" and "SavingsAccount is a class"
"SavingsAccount implements Account" is correct if and only if "Account is an interface" and "SavingsAccount is a class"
Which of the following is not part of the Collection interface?
Deque
List
HashMap
LinkedList
Ana is having a requirement, where she needs a method that processes the input from a file. The method has to read all the phone numbers from the file and store it in a collection, by eliminating the duplicates. Which collection suits to her requirement?
LIST
SET
STACK
HASHMAP
Consider the code snippet given below. How many threads are active at line numbers 1, 2, and 3 respectively?
public class MyThreadDemo implements Runnable
{
public void run()
{
System.out.println("Thread is running");
}
public static void main(String[] args)
{
MyThreadDemo obj = new MyThreadDemo();
Thread threadObj = new Thread(obj); // 1
threadObj.start(); // 2
threadObj.run();// 3
}
}
Code will provide a run time error
Code will provide an error on compilation
main thread,2, 3 respectively
main thread,2 respectively
What will be expected when the following snippet executes?
public class TestOne
{
public static void main(String[] args) throws Exception
{
Thread.sleep(3000);
System.out.println("sleep");
}
}
Compilation fails
An exception is thrown at runtime
The code executes normally and prints sleep
The code executes normally, but nothing is printed
Consider the following code snippet:
import java.util.List;
import java.util.ArrayList;
public class ListTester
{
public static void main(String[] args)
{
List<String> testList = new ArrayList<>();
testList.add(new String("hello"));
testList.add(new Integer(12));
}
}
Compilation Error check
Program will get executed successfully
Runtime Exception
None of the above
import java.util.List;
import java.util.ArrayList;
public class ListTester
{
public static void main(String[] args)
{
List<String> nameList = new ArrayList<>();
nameList.add(1,"One");
nameList.add(2,"Two");
for(String no:nameList)
{
System.out.println(no);
}
}
}
Compilation Error
One Two
Runtime Exception
None of the above
What is the output of this code?
class MyGen<T>
{
private T obj;
public void add(T obj)
{
this.obj = obj;
}
public T get()
{
return obj;
}
}
public class TestGenerics
{
public static void main(String args[])
{
MyGen<Integer> m = new MyGen<Integer>();
m.add(2); // line 7
m.add("5"); //line 8
System.out.println(m.get());
}
}
2
5
Compile time error at line 8
Compile time error at line 7
In which of the following package Exception class exist?
java.util
java.file
java.io
java.lang
In Java, when we implement an interface method, it must be declared as:
Private
Protected
Public
Friend
Which of these is not a Thread state?
New
Runnable
sleep
terminated
A thread can acquire a lock by using which reserved keyword?
volatile
synchronized
locked
none
What is difference between starting thread with run() and start() method?
There is no difference
When you call start() method, main thread internally calls run() method to start newly created Thread
run() calls start() method internally
None
