1. • Which of the following is correct syntax for an Abstract class ?
(a) abstract double area() { }
(b) abstract double area()
(c) abstract double area();
(d) abstract double area(); { }
ANS: (c)
• A class can be converted to a thread by implementing the interface __________
(a) Thread
(b) Runnable
ANS: (b)
• What is the output of following block of program ?
boolean var = false;
if(var = true) {
System.out.println("TRUE");
} else {
System.out.println("FALSE");
}
(a) TRUE
(b) FALSE
(c) Compilation Error
(d) Run-time Error
ANS: (a)
EXPLANATION: The code compiles and runs fine and the 'if' test succeeds because 'var' is set to
'true' (rather than tested for 'true') in the 'if' argument.
• A Vector is declared as follows. What happens if the code tried to add 6 th element to
this Vector new vector(5,10)
(a) The element will be successfully added
(b) ArrayIndexOutOfBounds Exception
2. (c) The Vector allocates space to accommodate up to 15 elements
ANS: (a) and (c)
EXPLANATION: The 1 st argument in the constructor is the initial size of Vector and the 2 nd
argument in the constructor is the growth in size (for each allocation)
This Vector is created with 5 elements and when an extra element (6 th one) is tried to be
added, the vector grows in size by 10.
• What is the output of following piece of code ?
int x = 2;
switch (x) {
case 1:System.out.println("1");
case 2:
case 3:System.out.println("3");
case 4:
case 5:System.out.println("5");
}
(a) No output
(b) 3 and 5
(c) 1, 3 and 5
(d) 3
ANS: (b)
• Which of the following 2 methods executes faster ?
class Trial {
String _member;
void method1() {
for(int i=0;i<2048;i++) {
_member += "test";
}
}
void method2() {
3. String temp;
for(int i=0;i<2048;i++) {
temp += "test";
}
_member = temp;
}
}
(a) method1()
(b) method2()
(c) Both method1() and method2() takes same time for execution
ANS: (b)
Accessing method variables requires less overhead than accessing class variables.
• Integer.parseInt("12a") returns
(a) Exception
(b) 1
(c) 0
(d) -1
ANS: (a)
• By default, Strings to functions are passed using the method
(a) Call by Value
(b) Call by Reference
(c) Strings cannot be passed to function
ANS: (b)
String is a class defined in java.lang and in java all classes are passed by reference.
4. • What is the output of following program ?
class Test {
public static void main(String args[]) {
for(int i=0;i<2;i++) {
System.out.println(i--);
}
}
}
(a) Goes into infinite loop
(b) 0,1
(c) 0,1,2
(d) None
ANS: (a)
• It is the reference to a class that extends THREAD. Then how to suspend the execution
of this thread?
(a) t.yield()
(b) yield(t)
(c) yield()
(d) yield(100) where 100 is the milli seconds of time
• How many String objects are created by the following statements ?
String str = " a+b=10 ";
trim(str)
str.replace(+,-);
(a) 1
(b) 2
(c) 3
(d) 4
5. ANS: (c)
• Cleaning operation in Java is done in the method
(a) finally()
(b) finalize()
(c) final()
• If we want to read a very big text file with so many mega bytes of data, what shall we
use ?
(a) FileInputStream
(b) InputStreamReader
• What code, if written, below the (//code here) will display 0.
class Test {
public static void main(String argv[]) {
int i=0;
//code here
}
}
(a) System.out.println(i++)
(b) System.out.println(i+'0')
(c) System.out.println(i--)
(d) System.out.println(i)
ANS: (a),(c),(d)
The option (b) displays the ASCII value of '0'. So, the output in this case is: 48
• Which one of the following about Applet is true? (Choose all that applies)
a. Applets are executed by console based-java run-time interpreter.
b. Applets are executed by a Web Browser
c. Applets are executed by an Applet Viewer
6. d. None of the Above
• In applets which method is used to allocate memory to the components?
a) start()
b) stop()
c) init()
d) destroy()
• While executing applets in browser the tag specified in the HTML browser is
a) <html></html>
b) <appletviewer></appletviewer>
c) <applet></applet>
d) <xml></xml>
• Which of the following method is used to retrieve the base URL of the applet
a) getAppletInfo()
b) getDocumentInfo()
c) getDocumentBase()
d) getCodeBase()
• The method used in applet to display image in the status bar is
a) showInfo()
b) showStatus()
c) dialogStatus()
d) dialogInfo()
• The method used to dynamically specify the size to the applet is
7. a) pack()
b) size()
c) resize()
d) height, width
• Expand AWT
a) Applet Windows Tool Kit.
b) Applications Windows Tool Kit
c) Abstract Windows Tool Kit
d) None of the Above
• Which one of the following is an Abstract Class?
a. Graphics
b. Color
c. Menu
d. Font
e. None of the above
• Which of the following is the default Layout Manager in Java?
a. Border Layout Manager
b. Flow Layout Manager
c. Grid Bag Layout Manager
d. Card Layout
e. None of the Above.
• In which Layout Manager extra space is placed in the Center region ?
a) Border Layout Manager
8. b) Flow Layout Manager
c) Grid Bag Layout Manager
d) Card Layout
e) None of the Above.
• In which Layout Manager the container is divided into equally-sized
rectangles, and one components is placed in the rectangles
a. Border Layout Manager
b. Flow Layout Manager
c. Grid Bag Layout Manager
d. Card Layout
e. Grid Layout
f. None of the Above.
• Which of the following are the features of swing components?
a. Lightweight
b. Portable
c. Look & Feel
d. All the above
• MVC stands for
a. Model View Controller
b. Model View Container
c. Meta View Container
9. d. Model Volatile Container
• Swing components are categorized into
a. Applets and Applications
b. Frames and Panels
c. Containers and Controls
d. none of above
• Window Event can be activated on the containers like
a) JFrame
b) JPanel
c) Component
d) Controls
• The method used to alter the displayed set of characters in the
components like password field is
a. setText()
b. setLabel()
c. echoChar()
d. setEchoChar()
• The method used to add element in the combobox is
a. addItem()
b. addElement()
c. addValue()
d. setElement()
• Which methods is used to separate different menu items in the menu bar