Test : Java_2
This test contains 10 questions based on Java.
Each question answered correctly awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for unattempted answers.
Each question answered correctly awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for unattempted answers.
Select Test Type
You Get +1 for each correct answer and -0.25 for each incorrect answer
Time Left - minutes :seconds
What is the output of this program?
class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj1 = new box(); box obj2 = new box(); obj1.height = 1; obj1.length = 2; obj1.width = 1; obj2 = obj1; System.out.println(obj2.height); } }
1 | 2 |
Runtime error | Garbage value |
What is the output of this program?
class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
2 2 | 2 3 |
3 2 | 3 3 |
Which of the following statements are true?
(A) A Java monitor must either extend Thread or implement Runnable.
(B) The sleep() method should be enclosed in try ... catch block.
(C) The yield() method should be enclosed in try ... catch block.
(D) A thread can be temporarily suspended from running by using the wait() method.
(E) A suspended thread using suspend() method can be revived using the resume() method.
(A), (B), (D) & (E | (D) & (E) |
(A), (B) & (D) | (B), (D) & (E) |
What is the result of attempting to compile and run the program?
- class BaseException extends Exception {}
- class SubException extends BaseException {}
- public class TestClass {
- void method1() throws BaseException {throw new SubException();}
- void method2() throws SubException {}
- public static void main (String[] args) {
- TestClass objTest = new TestClass();
- int i,j,k,l;
- i = j = k = l = 10;
- try {objTest.method1(); i++;} catch (BaseException e) {j++;}
- try {objTest.method2(); k++;} catch (SubException e) {l++;}
- System.out.print(i+","+j+","+k+","+l);
- }
- }
Prints: 10,11,10,10 | Prints: 11,11,10,10 |
Prints: 10,11,11,10 | Prints: 11,11,11,10 |
What is the output of this program?
class A { public int i; protected int j; } class B extends A { int j; void display() { super.j = 3; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
2 1 | 1 2 |
3 1 | 1 3 |
What is the output of this program?
class string_class { public static void main(String args[]) { String obj = "hello"; String obj1 = "world"; String obj2 = "hello"; System.out.println(obj.equals(obj1) + " " + obj.equals(obj2)); } }
true true | false false |
true false | false true |
what will be the output
int a=2;
int b=3;
System.out.println(a+""+b);
2 3 | 3 |
5 | 23 |
What is the output of this program?
class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }
My Thread | Thread[My Thread,5,main] |
Compilation Error | Runtime Error |
What is the output of this program?
class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { Thread.sleep(1000); System.out.print(obj1.t.isAlive()); } catch(InterruptedException e) { System.out.print("Main thread interrupted"); } } }
true | false |
Which of these methods is a part of Abstract Window Toolkit (AWT) ?
display() | print() |
transient() | drawString() |
Finish Test
No comments: