Main.
java
public class Main{
public static void main(String[] args){
Quad qc = new Quad(2,5,3,20.1);
Quad.Disc dc = qc.new Disc();
dc.display();
qc.displayOuter();
}
}
Quad.java
public class Quad {
public int a;
public int b;
public int c;
private double d;
public Quad(int a, int b, int c, double d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public class Disc{
private int d = 15;
public void display(){
System.out.println("The value of d is : " +d);
System.out.println("The value of a is :" +a);
}
}
}
Question 13/20
Prev
Next
What happens if you attempt to catch an exception of a type that is not a superclass of the thrown exception?
The exception will be rethrown automatically.
A compile-time error will occur.
The catch block will execute.
The code will not compile.
Explanation
In Java, a catch block can only catch exceptions that are either of the same type or a superclass of the thrown exception. Attempting to catch an
unrelated exception results in a compilation error.
Question 9/10
Prev
Next
Which of these exception is thrown in cases when the file specified for writing is not found?
IOException
FileException
FileNotFoundException
FileInputException
Explanation
In cases when the file specified is not found, then FileNotFoundException is thrown.
What will be the output of the following java code?
class Prepinsta
Prepinsta()throws IOException
class Main extends Prepinsta
Main()
{
public static void main(String[]args)
Compile time error
Run time error
Compile and run fine
Unreported exception java.io.IOException in default constructor
Explanation
If the parent class constructor throws any checked exception , the compulsory child class constructor should throw the same checked exception
as its parent , otherwise the code won’t compile.
Question 2/20
Prev
Next
Executing several tasks simultaneously where each task is a separate independent part of the same program, is called?
None of the above
Task based multitasking
Thread based multitasking
Process based multitasking
Explanation
Executing several tasks simultaneously where each task is a separate independent part of the same program, is called Thread based multitasking.
Question 3/20
Prev
Next
How many types of multitasking are there in java ?
Three
Four
Two
One
Explanation
Executing several tasks simultaneously is the concept of multitasking. There are two types of multitasking.
1) Process based multitasking.
2) Thread based multitasking.
Question 4/20
Prev
Next
Which method is used to interrupt a sleeping or waiting Thread of Thread class ?
sleep()
yield()
join()
interrupt()
Explanation
We can interrupt a sleeping or waiting thread by using the interrupt() method of Thread class.
Java uses threads to enable the entire environment to be asynchronous. Asynchronous threading is pre-emptive i.e. once a thread starts executing
a task it can hold it in mid, save the current state and start executing another task (context switching) according to priority and other specified
criteria and threading.so ,option (A) is correct.
Question 12/20
Prev
Next
What will be the output of the following program?
class MyThread extends Thread
public void run()
run(1);
public void run(int i)
System.out.println("int arg method");
class Main
public static void main(String[] args)
MyThread t=new MyThread();
t.start();
Run time error
Compile time error
No output
int arg method
Explanation
Thread class start() method invokes no argument run() method which invokes other overload run() methods just like normal method.Hence, the
output of the program will be “int arg method”.
class MyThread extends Thread
public void start()
System.out.print("start method ");
public void run()
System.out.print("run method ");
class Main
public static void main(String[] args)
MyThread t=new MyThread();
t.start();
}
}
run method start method
start method run method
start method
run method
Question 11/20
Prev
Next
Which of the following functional interface represents a function that accepts a double-valued argument and produces a result?
DoubleToIntFunction
DoubleSupplier
DoublePredicate
DoubleFunction<R>
Explanation
DoubleFunction<R> functional interface represents a function that accepts a double-valued argument and produces a result.
Question 16/20
Prev
Next
What is the purpose of BooleanSupplier function interface?
represents supplier of Boolean-valued results
returns null if Boolean is passed as argument
There is no such function interface
returns Boolean-valued result
Explanation
BooleanSupplier function interface represents supplier of Boolean-valued results.
Which feature of java 8 enables us to create a work stealing thread pool using all available processors at its target?
threadPool
workThreadPool
newWorkStealingPool
workPool
Explanation
Executors newWorkStealingPool() method to create a work-stealing thread pool using all available processors as its target parallelism level.
Question 3/10
Prev
Next
What is the need of lambda expression in java ?
To enable procedural programming in java
To enable functional programming in java
To enable object oriented feature in java
None of the above
Explanation
The need of lambda expression in java is to enable functional programming.
Which among the following is not a functional interface ?
Runnable
Callable
Comparable
Serializable
Explanation
An interface which contains only one abstract method is called a functional interface.
Example:
Runnable⇒ run()
Callable=> call()
Comparable => compareTo()
Serializable interface doesn’t contain any method. Hence, it is a marker interface.
Question 7/10
Prev
Next
What will be the output of the following program?
@FunctionalInterface
interface Inter1
public abstract void methodOne();
class Main
public static void main(String[] args)
Inter1 m=()->System.out.println("Hello Prepsters");
m.methodOne();
}
Hello Prepsters
No output
Compile time error
Run time error
Explanation
Inter1 is a functional interface as it contains only one abstract method, hence we can write a lambda expression for it. Hence the output of the
program is “Hello Prepsters”