Ubinetics Previous Years Solved Sample Placement Papers
- What will be the output of the following Java program?
class exception_handling { public static void main(String args[]) { try { int a, b; b = 0; a = 5 / b; System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } } }
a) A b) B c) Compilation Error d) Runtime Error Answer: b) B Explanation: A division by zero causes an ArithmeticException, which is caught by the catch block, printing "B". Output:$ javac exception_handling.java $ java exception_handling B
- What will be the output of the following Java program?
class exception_handling { public static void main(String args[]) { try { int a, b; b = 0; a = 5 / b; System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } finally { System.out.print("C"); } } }
a) A b) B c) AC d) BC Answer: d) BC Explanation: TheArithmeticException
is caught by the catch block, printing "B", and the finally block is executed, printing "C". Output:$ javac exception_handling.java $ java exception_handling BC
- What will be the output of the following Java program?
class exception_handling { public static void main(String args[]) { try { int i, sum; sum = 10; for (i = -1; i < 3 ;++i) sum = (sum / i); } catch(ArithmeticException e) { System.out.print("0"); } System.out.print(sum); } }
a) 0 b) 05 c) Compilation Error d) Runtime Error Answer: c) Compilation Error Explanation: The variablesum
is declared inside the try block, making it out of scope when accessed outside the try block, resulting in a compilation error. Output:$ javac exception_handling.java Exception in thread "main" java.lang.Error: Unresolved compilation problem: sum cannot be resolved to a variable
- Which of the following is true about servlets?
a) Servlets can use the full functionality of the Java class libraries b) Servlets execute within the address space of web server, platform independent and uses the functionality of java class libraries c) Servlets execute within the address space of web server d) Servlets are platform-independent because they are written in java
Answer: b) Servlets execute within the address space of web server, platform independent and uses the functionality of java class libraries Explanation: Servlets execute within the address space of a web server. Since they are written in Java, they are platform-independent, and the full functionality of Java class libraries is available. - What will be the output of the following Java program?
class exception_handling { public static void main(String args[]) { try { System.out.print("Hello" + " " + 1 / 0); } catch(ArithmeticException e) { System.out.print("World"); } } }
Answer: b) World Explanation: The1 / 0
causes anArithmeticException
, which is caught by thecatch
block, printing "World". Output:$ javac exception_handling.java $ java exception_handling World
-
The word synchronized can be used with only a method. True/False
A: False
Ans: False -
What are all the four states associated in the thread?
A: 1. new 2. runnable 3. blocked 4. dead
Ans: 1. new 2. runnable 3. blocked 4. dead -
The suspend() method is used to terminate a thread. True/False
A: False
Ans: False -
The run() method should necessarily exist in classes created as subclass of thread. True/False
A: True
Ans: True -
Garbage collector thread belongs to which priority?
A: low-priority
Ans: low-priority -
What is the difference between superclass & subclass?
A: A superclass is a class that is inherited whereas subclass is a class that does the inheriting.
Ans: A superclass is a class that is inherited whereas subclass is a class that does the inheriting. -
Which keyword is used to inherit a class?
A: extends
Ans: extends -
Object class is a superclass of all other classes? True/False
A: True
Ans: True -
Java supports multiple inheritance? True/False
A: False
Ans: False -
What is inheritance?
A: Deriving an object from an existing class. In other words, inheritance is the process of inheriting all the features from a class.
Ans: Deriving an object from an existing class. In other words, inheritance is the process of inheriting all the features from a class. -
What are the advantages of inheritance?
A: Reusability of code and accessibility of variables and methods of the superclass by subclasses.
Ans: Reusability of code and accessibility of variables and methods of the superclass by subclasses. -
Which methods are used to destroy the objects created by the constructor methods?
A: finalize()
Ans: finalize() -
What are abstract classes?
A: Abstract classes are those for which instances can’t be created.
Ans: Abstract classes are those for which instances can’t be created. -
What must a class do to implement an interface?
A: It must provide all of the methods in the interface and identify
-
What is the method available for setting the priority?
A: setPriority()
Ans: setPriority() -
What is the default thread at the time of starting the program?
A: main thread
Ans: main thread