Applets Fundamentals(Computer Science > Java Program ) Questions and Answers
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();
}
}
}
Explanation:-
Answer: Option D. -> None of the mentionedNo 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
Explanation:-
Answer: Option C. -> Compilation ErrorTo implement the method drawString we need first need to define abstract method
Explanation:-
Answer: Option A. -> 20the code in pain() method - g.drawString("A Simple Applet",20,20); draws a applet
box of length 20 and width 20.
Explanation:-
Answer: Option A. -> A Simple AppletNone.
Output:
A Simple Applet
(Output comes in a new java application)
Explanation:-
Answer: Option B. -> volatileThe 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.