Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.


What is the output of this program?


import java.io.*;
class Chararrayinput {
public static void main(String[] args) {
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i;
int j;
try {
while((i = input1.read()) == (j = input2.read())) {
System.out.print((char)i);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
  1.    abc
  2.    abcd
  3.    abcde
  4.    None of the mentioned
 Discuss Question
Answer: Option D. -> None of the mentioned

No output is printed. CharArrayReader object input1 contains string "abcdefgh" 

whereas object input2 contains string "bcde", when while((i=input1.read())==

(j=input2.read())) is executed the starting character of each object is compared

 since they are unequal control comes out of loop and nothing is printed on the screen.
Output:
$ javac Chararrayinput.java
$ java Chararrayinput



Question 2.


What is the length of the application box made by this program?


import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
Graphic g;
g.drawString("A Simple Applet", 20, 20);
}
  1.    20
  2.    Default value
  3.    Compilation Error
  4.    Runtime Error
 Discuss Question
Answer: Option C. -> Compilation Error

To implement the method drawString we need first need to define abstract method 

Question 3.


What is the length of the application box made by this program?


import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20, 20);
}
}
  1.    20
  2.    50
  3.    100
  4.    System dependent
 Discuss Question
Answer: Option A. -> 20

the code in pain() method - g.drawString("A Simple Applet",20,20); draws a applet 

box of length 20 and width 20.



Question 4.


What is the Message is displayed in the applet made by this program?


import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20, 20);
}
}
  1.    A Simple Applet
  2.    A Simple Applet 20 20
  3.    Compilation Error
  4.    Runtime Error
 Discuss Question
Answer: Option A. -> A Simple Applet

None.
Output:
A Simple Applet
(Output comes in a new java application)


Question 5.

Which of these operators can be used to get run time information about an object?


  1.    getInfo
  2.    Info
  3.    instanceof
  4.    getinfoof
 Discuss Question
Answer: Option C. -> instanceof

None.

Question 6.

Which of these modifiers can be used for a variable so that it can be accessed 

from any thread or parts of a program?


  1.    transient
  2.    volatile
  3.    global
  4.    No modifier is needed
 Discuss Question
Answer: Option B. -> volatile

The volatile modifier tells the compiler that the variable modified by volatile can be 

changed unexpectedly by other part of the program. Specially used in situations 

involving multithreading.



Question 7.

Which of these methods is a part of Abstract Window Toolkit (AWT) ?


  1.    display()
  2.    print()
  3.    drawString()
  4.    transient()
 Discuss Question
Answer: Option B. -> print()

paint() is an abstract method defined in AWT.


Question 8.

What does AWT stands for?


  1.    All Window Tools
  2.    All Writing Tools
  3.    Abstract Window Toolkit
  4.    Abstract Writing Toolkit
 Discuss Question
Answer: Option C. -> Abstract Window Toolkit

AWT stands for Abstract Window Toolkit, it is used by applets to interact with the user.


Question 9.

Which of these methods can be used to output a sting in an applet?


  1.    display()
  2.    print()
  3.    drawString()
  4.    transient()
 Discuss Question
Answer: Option C. -> drawString()

drawString() method is defined in Graphics class, it is used to output a string 

in an applet.


Question 10.

Which of these functions is called to display the output of an applet?


  1.    display()
  2.    print()
  3.    displayApplet()
  4.    PrintApplet()
 Discuss Question
Answer: Option B. -> print()

Whenever the applet requires to redraw its output, it is done by using method paint().


Latest Videos

Latest Test Papers