Sail E0 Webinar

MCQs

Total Questions : 47 | Page 1 of 5 pages
Question 1.

Which of these events will be generated if we close an applet's window?


  1.    ActionEvent
  2.    ComponentEvent
  3.    AdjustmentEvent
  4.    WindowEvent
 Discuss Question
Answer: Option D. -> WindowEvent

WindowEvent is generated when a window is activated, closed, deactivated, 

deiconfied, iconfied, opened or quit.


Question 2.


What is the name of the thread in output of this program?


class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t.isAlive());
}
}
  1.    0
  2.    1
  3.    true
  4.    false
 Discuss Question
Answer: Option A. -> 0

Thread t is seeded to currently program, hence when you run the program the thread 

becomes active & code 't.isAlive' returns true.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
true



Question 3.


What is the output of this program?


class output {
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
  1.    Hello
  2.    olleH
  3.    HelloolleH
  4.    olleHHello
 Discuss Question
Answer: Option B. -> olleH

reverse() method reverses all characters. It returns the reversed object on which it was called.
Output:
$ javac output.java
$ java output
olleH


Question 4.


What is the output of this 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);
System.out.print(i);
}
}
catch(ArithmeticException e) {
System.out.print("0");
}
}
}
  1.    -1
  2.    0
  3.    -10
  4.    -101
 Discuss Question
Answer: Option C. -> -10

For the 1st iteration -1 is displayed. The 2nd exception is caught in catch block and 0 

is displayed.
Output:
$ javac exception_handling.java
$ java exception_handling
-10


Question 5.

Which of these events will be notified if scroll bar is manipulated?


  1.    ActionEvent
  2.    ComponentEvent
  3.    AdjustmentEvent
  4.    WindowEvent
 Discuss Question
Answer: Option C. -> AdjustmentEvent

AdjustmentEvent is generated when a scroll bar is manipulated.


Question 6.


What is the name of the thread in output of this program?


class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t);
}
}
  1.    main
  2.    Thread
  3.    System
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> main

The output of program is Thread[main,5,main], Since we have not explicitly named the 

thread they are named by the group to they belong i:e main method. Hence they are 

named ‘main’.

Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]


Question 7.


What is the output of this 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);
}
}
  1.    0
  2.    05
  3.    Compilation Error
  4.    Runtime Error
 Discuss Question
Answer: Option C. -> Compilation Error

Value of variable sum is printed outside of try block, sum is declared only in try block, 

outside try block it is undefined.
Output:
$ javac exception_handling.java
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
sum cannot be resolved to a variable


Question 8.

Which of these class is super class of all the events?


  1.    EventObject
  2.    EventClass
  3.    ActionEvent
  4.    ItemEvent
 Discuss Question
Answer: Option A. -> EventObject

EventObject class is a super class of all the events and is defined in java.util package.

Question 9.


What is the priority of the thread in output of this program?


class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t);
}
}
  1.    4
  2.    5
  3.    0
  4.    1
 Discuss Question
Answer: Option B. -> 5

The output of program is Thread[main,5,main], in this priority assigned to the thread

is 5. Its the default value.  Since  we have not named  the thread they  are named by 

the group to they belong i:e main method.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]


Question 10.


What is the output of this program?


class output {
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
System.out.println(c.length());
}
}
  1.    4
  2.    5
  3.    6
  4.    7
 Discuss Question
Answer: Option B. -> 5

length() method is used to obtain length of StringBuffer object, length of "Hello" is 5.
Output:
$ javac output.java
$ java output
5


Latest Videos

Latest Test Papers