MCQs
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();
}
}
}
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
To implement the method drawString we need first need to define abstract method
the code in pain() method - g.drawString("A Simple Applet",20,20); draws a applet
box of length 20 and width 20.
None.
Output:
A Simple Applet
(Output comes in a new java application)
None.
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.
paint() is an abstract method defined in AWT.
AWT stands for Abstract Window Toolkit, it is used by applets to interact with the user.
drawString() method is defined in Graphics class, it is used to output a string
in an applet.
Whenever the applet requires to redraw its output, it is done by using method paint().