Vous êtes sur la page 1sur 312

Cracked By Charitra Choudhary

Any Help, Plz Feel Free to mail (Charitra.choudharyrediIImail.com)


MCSE, MCSE, CCNA, Comptia A, N, JCP, MCAD, MCSD, MVP



Question 1)
Which oI the Iollowing lines will compile without warning or error.
1) Iloat I1.3;
2) char c"a";
3) byte b257;
4) boolean bnull;
5) int i10;

Question 2)
What will happen iI you try to compile and run the Iollowing code
public class MyClass
public static void main(String arguments||)
amethod(arguments);
}
public void amethod(String|| arguments)
System.out.println(arguments);
System.out.println(arguments|1|);
}
}
1) error Can't make static reIerence to void amethod.
2) error method main not correct
3) error array must include parameter
4) amethod must be declared with String

Question 3)
Which oI the Iollowing will compile without error
1)
import java.awt.*;
package Mypackage;
class Myclass }
2)
package MyPackage;
import java.awt.*;
class MyClass}
3)
/*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass}

Question 4)
A byte can be oI what size
1) -128 to 127
2) (-2 power 8 )-1 to 2 power 8
3) -255 to 256
4)depends on the particular implementation oI the Java Virtual machine


Question 5)
What will be printed out iI this code is run with the Iollowing command line?
java myprog good morning
public class myprog
public static void main(String argv||)

System.out.println(argv|2|)
}
}
1) myprog
2) good
3) morning
4) Exception raised: "java.lang.ArrayIndexOutOIBoundsException: 2"


Question 6)
Which oI the Iollowing are keywords or reserved words in Java?
1) iI
2) then
3) goto
4) while
5) case


Question 7)
Which oI the Iollowing are legal identiIiers
1) 2variable
2) variable2
3) whatavariable
4) 3
5) $anothervar
6) #myvar


Question 8)
What will happen when you compile and run the Iollowing code?

public class MyClass
static int i;
public static void main(String argv||)
System.out.println(i);
}
}
1) Error Variable i may not have been initialized
2) null
3) 1
4) 0


Question 9)
What will happen iI you try to compile and run the Iollowing code?
public class Q
public static void main(String argv||)
int anar||new int||1,2,3};
System.out.println(anar|1|);
}
}
1) 1
2) Error anar is reIerenced beIore it is initialized
3) 2
4) Error: size oI array must be deIined


Question 10)

What will happen iI you try to compile and run the Iollowing code?
public class Q
public static void main(String argv||)
int anar||new int|5|;
System.out.println(anar|0|);
}
}
1) Error: anar is reIerenced beIore it is initialized
2) null
3) 0
4) 5


Question 11)

What will be the result oI attempting to compile and run the Iollowing code?
abstract class MineBase
abstract void amethod();
static int i;
}
public class Mine extends MineBase
public static void main(String argv||)
int|| arnew int|5|;
Ior(i0;i ar.length;i)
System.out.println(ar|i|);
}
}
1) a sequence oI 5 0's will be printed
2) Error: ar is used beIore it is initialized
3) Error Mine must be declared abstract
4) IndexOutOIBoundes Error


Question 12)
What will be printed out iI you attempt to compile and run the Iollowing code ?
int i1;
switch (i)
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
deIault:
System.out.println("deIault");
}
1) one
2) one, deIault
3) one, two, deIault
4) deIault


Question 13)
What will be printed out iI you attempt to compile and run the Iollowing code?
int i9;
switch (i)
deIault:
System.out.println("deIault");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
1) deIault
2) deIault, zero
3) error deIault clause not deIined
4) no output displayed


Question 14)
Which oI the Iollowing lines oI code will compile without error
1)
int i0;
iI(i)
System.out.println("Hello");
}
2)
boolean btrue;
boolean b2true;
iI(bb2)
System.out.println("So true");
}
3)
int i1;
int j2;
iI(i1,, j2)
System.out.println("OK");
4)
int i1;
int j2;
iI(i1 &, j2)
System.out.println("OK");


Question 15)
What will be output iI you try to compile and run the Iollowing code, but there is
no Iile called Hello.txt in the current directory?.
import java.io.*;
public class Mine
public static void main(String argv||)
Mine mnew Mine();
System.out.println(m.amethod());
}
public int amethod()
try
FileInputStream disnew FileInputStream("Hello.txt");
}catch (FileNotFoundException Ine)
System.out.println("No such Iile Iound");
return -1;
}catch(IOException ioe)
} Iinally
System.out.println("Doing Iinally");
}
return 0;
}
}
1) No such Iile Iound
2 No such Iile Iound ,-1
3) No such Iile Iound, Doing Iinally, -1
4) 0


Question 16)
Which oI the Iollowing statements are true?
1) Methods cannot be overriden to be more private
2) Static methods cannot be overloaded
3) Private methods cannot be overloaded
4) An overloaded method cannot throw exceptions not checked in the base class


Question 17)
What will happen iI you attempt to compile and run the Iollowing code?
1) Compile and run without error
2) Compile time Exception
3) Runtime Exception
class Base }
class Sub extends Base }
class Sub2 extends Base }
public class CEx
public static void main(String argv||)
Base bnew Base();
Sub s(Sub) b;
}
}


Question 18)
II the Iollowing HTML code is used to display the applet in the code MgAp what will
be displayed at the console?
1) Error: no such parameter
2) 0
3) null
4) 30
applet nameMgAp codeMgAp.class height400 width400 parameter HowOld30 ~
/applet~
import java.applet.*;
import java.awt.*;
public class MgAp extends Applet
public void init()
System.out.println(getParameter("age"));
}
}



Question 19)
You are browsing the Java HTML documentation Ior inIormation on the
java.awt.TextField component. You want to create Listener code to respond to Iocus
events. The only Listener method listed is addActionListener. How do you go about
Iinding out about Listener methods?
1) DeIine your own Listener interIace according to the event to be tracked
2) Use the search Iacility in the HTML documentation Ior the listener needed
3) Move up the hierarchy in the HTML documentation to locate methods in base
classes
4) Subclass awt.event with the appropriate Listener method


Question 20)

What will be displayed when you attempt to compile and run the Iollowing code
//Code start
import java.awt.*;
public class Butt extends Frame
public static void main(String argv||)
Butt MyButnew Butt();
}
Butt()
Button HelloButnew Button("Hello");
Button ByeButnew Button("Bye");
add(HelloBut);
add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
//Code end
1) Two buttons side by side occupying all oI the Irame, Hello on the leIt and Bye on
the right
2) One button occupying the entire Irame saying Hello
3) One button occupying the entire Irame saying Bye
4) Two buttons at the top oI the Irame one saying Hello the other saying Bye


Question 21)

What will be output by the Iollowing code?
public class MyFor
public static void main(String argv||)
int i;
int j;
outer:
Ior (i1;i 3;i)
inner:
Ior(j1; j3; j)
iI (j2)
continue outer;
System.out.println("Value Ior i" i " Value Ior j" j);
}
}
}
1) Value Ior i1 value Ior j1
2) Value Ior i2 value Ior j1
3) Value Ior i2 value Ior j2
4) Value Ior i3 value Ior j1


Question 22)

II g is a graphics instance what will the Iollowing code draw on the screen?.
g.IillArc(45,90,50,50,90,180);
1) An arc bounded by a box oI height 45, width 90 with a centre point oI 50,50, starting
at an angle oI 90 degrees traversing through 180 degrees counter clockwise.
2) An arc bounded by a box oI height 50, width 50, with a centre point oI 45,90 starting
at an angle oI 90 degrees traversing through 180 degrees clockwise.
3) An arc bounded by a box oI height 50, width 50, with a top leIt at coordinates oI 45,
90, starting at 90 degrees and traversing through 180 degrees counter clockwise.
4) An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a
box oI height 50, width 50 with a centre point oI 90, 180.


Question 23)

Which oI the Iollowing methods can be legally inserted in place oI the comment
//Method Here ?
class Base
public void amethod(int i) }
}
public class Scope extends Base
public static void main(String argv||)
}
//Method Here
}
1) void amethod(int i) throws Exception }
2) void amethod(long i)throws Exception }
3) void amethod(long i)}
4) public void amethod(int i) throws Exception }


Question 24)

Which oI the Iollowing will output -4.0
1) System.out.println(Math.Iloor(-4.7));
2) System.out.println(Math.round(-4.7));
3) System.out.println(Math.ceil(-4.7));
4) System.out.println(Math.min(-4.7));


Question 25)

What will happen iI you attempt to compile and run the Iollowing code?
Integer tennew Integer(10);
Long ninenew Long (9);
System.out.println(ten nine);
int i1;
System.out.println(i ten);
1) 19 Iollowed by 20
2) 19 Iollowed by 11
3) Error: Can't convert java lang Integer
4) 10 Iollowed by 1


Question 26)

II you run the code below, what gets printed out?
String snew String("Bicycle");
int iBegin1;
char iEnd3;
System.out.println(s.substring(iBegin,iEnd));
1) Bic
2) ic
3) icy
4) error: no method matching substring(int,char)


Question 27)
II you wanted to Iind out where the position oI the letter v (ie return 2) in the string s
containing "Java", which oI the Iollowing could you use?
1) mid(2,s);
2) charAt(2);
3) s.indexOI('v');
4) indexOI(s,'v');


Question 28)
Given the Iollowing declarations
String s1new String("Hello")
String s2new String("there");
String s3new String();
Which oI the Iollowing are legal operations?
1) s3s1 s2;
2) s3s1-s2;
3) s3s1 & s2;
4) s3s1 && s2


Question 29)
What is the result oI the Iollowing operation?
System.out.println(4 , 3);
1) 6
2) 0
3) 1
4) 7


Question 30)
public class MyClass1
public static void main(String argv||) }
/*ModiIier at XX */ class MyInner }
}
What modiIiers would be legal at XX in the above code?
1) public
2) private
3) static
4) Iriend


Question 31)

How would you go about opening an image Iile called MyPicture.jpg
1) Graphics.getGraphics("MyPicture.jpg");
2) Image imageToolkit.getDeIaultToolkit().getImage("MyPicture.jpg");
3) Graphics.openImage("MyPicture");
4) Image mnew Image("MyPicture");

Question 32)
An Applet has its Layout Manager set to the deIault oI FlowLayout. What code would be
correct to change to another Layout Manager.
1) setLayoutManager(new GridLayout());
2) setLayout(new GridLayout(2,2));
3) setGridLayout(2,2);
4) setBorderLayout();


Question 33)

What will happen when you attempt to compile and run the Iollowing code?.
1) It will compile and the run method will print out the increasing value oI i.
2) It will compile and calling start will print out the increasing value oI i.
3) The code will cause an error at compile time.
4) Compilation will cause an error because while cannot take a parameter oI true.
class Background implements Runnable
int i0;
public int run()
while(true)
i;
System.out.println("i"i);
} //End while

return 1;
}//End run
}//End class



Question 34)
You have created an applet that draws lines. You have overriden the paint operation and
used the graphics drawLine method, and increase one oI its parameters to multiple lines
across the screen. When you Iirst test the applet you Iind that the news lines are redrawn,
but the old lines are erased. How can you modiIy your code to allow the old lines to stay
on the screen instead oI being cleared.
1) Override repaint thus
public void repaint(Graphics g)
paint(g);
}
2)Override update thus
public void update(Graphics g)
paint(g);
}
3) turn oII clearing with the method setClear();
4) Remove the drawing Irom the paint Method and place in the calling code


Question 35)

What will be the result when you attempt to compile and run the Iollowing code?.
public class Conv
public static void main(String argv||)
Conv cnew Conv();
String snew String("ello");
c.amethod(s);
}
public void amethod(String s)
char c'H';
cs;
System.out.println(c);
}
}
1) Compilation and output the string "Hello"
2) Compilation and output the string "ello"
3) Compilation and output the string elloH
4) Compile time error


Question 36)
Given the Iollowing code, what test would you need to put in place oI the comment line?
//place test here
to result in an output oI
Equal
public class EqTest
public static void main(String argv||)
EqTest enew EqTest();
}
EqTest()
String s"Java";
String s2"java";
//place test here
System.out.println("Equal");
}else

System.out.println("Not equal");
}
}
}
1) iI(ss2)
2) iI(s.equals(s2)
3) iI(s.equalsIgnoreCase(s2))
4)iI(s.noCaseMatch(s2))


Question 37)
Given the Iollowing code
import java.awt.*;
public class SetF extends Frame
public static void main(String argv||)
SetF snew SetF();
s.setSize(300,200);
s.setVisible(true);
}
}
How could you set the Irame surIace color to pink
1)s.setBackground(Color.pink);
2)s.setColor(PINK);
3)s.Background(pink);
4)s.colorColor.pink


Question 38)

How can you change the current working directory using an instance oI the File class
called FileName?
1) FileName.chdir("DirName")
2) FileName.cd("DirName")
3) FileName.cwd("DirName")
4) The File class does not support directly changing the current directory.


Question 39)
II you create a TextField with a constructor to set it to occupy 5 columns, what diIIerence
will it make iI you use it with a proportional Iont (ie Times Roman) or a Iixed pitch
typewriter style Iont (Courier).
1)With a Iixed Iont you will see 5 characters, with a proportional it will depend on the
width oI the characters
2)With a Iixed Iont you will see 5 characters,with a proportional it will cause the Iield to
expand to Iit the text
3)The columns setting does not aIIect the number oI characters displayed
4)Both will show exactly 5 characters


Question 40)

Given the Iollowing code how could you invoke the Base constructor that will print out
the string "base constructor";
class Base
Base(int i)
System.out.println("base constructor");
}
Base()
}
}
public class Sup extends Base
public static void main(String argv||)
Sup s new Sup();
//One
}
Sup()

//Two
}
public void derived()

//Three
}
}
1) On the line AIter //One put Base(10);
2) On the line AIter //One put super(10);
3) On the line AIter //Two put super(10);
4) On the line AIter //Three put super(10);


Question 41)
Given the Iollowing code what will be output?
public class Pass
static int j20;
public static void main(String argv||)
int i10;
Pass p new Pass();
p.amethod(i);
System.out.println(i);
System.out.println(j);
}
public void amethod(int x)
xx*2;
jj*2;
}
}
1) Error: amethod parameter does not match variable
2) 20 and 40
3) 10 and 40
4) 10, and 20


Question 42)

What code placed aIter the comment //For loop would populate the elements oI the array
ia|| with values oI the variable i.?
public class Lin
public static void main(String argv||)
Lin l new Lin();
l.amethod();
}
public void amethod()
int ia|| new int|4|;
//Start For loop

ia|i|i;
System.out.println(ia|i|);
}
}
}
1) Ior(int i0; i ia.length() -1; i)
2) Ior (int i0; i ia.length(); i)
3) Ior(int i1; i 4; i)
4) Ior(int i0; i ia.length;i)


Question 43)

What will be the result when you try to compile and run the Iollowing code?
private class Base
Base()
int i 100;
System.out.println(i);
}
}
public class Pri extends Base
static int i 200;
public static void main(String argv||)
Pri p new Pri();
System.out.println(i);
}
}
1) Error at compile time
2) 200
3) 100 Iollowed by 200
4) 100


Question 44)
What will the Iollowing code print out?
public class Oct
public static void main(String argv||)
Oct o new Oct();
o.amethod();
}
public void amethod()
int oi 012;
System.out.println(oi);
}
}
1)12
2)012
3)10
4)10.0


Question 45
What will happen when you try compiling and running this code?
public class ReI
public static void main(String argv||)
ReI r new ReI();
r.amethod(r);
}
public void amethod(ReI r)
int i99;
multi(r);
System.out.println(i);
}
public void multi(ReI r)
r.i r.i*2;
}
}
1) Error at compile time
2) An output oI 99
3) An output oI 198
4) An error at runtime


Question 46)
You need to create a class that will store a unique object elements. You do not need to
sort these elements but they must be unique.
What interIace might be most suitable to meet this need?
1)Set
2)List
3)Map
4)Vector


Question 47)
Which oI the Iollowing will successIully create an instance oI the Vector class and add an
element?
1) Vector vnew Vector(99);
v|1|99;
2) Vector vnew Vector();
v.addElement(99);
3) Vector vnew Vector();
v.add(99);
4 Vector vnew Vector(100);
v.addElement("99");


Question 48)
You have created a simple Frame and overridden the paint method as Iollows
public void paint(Graphics g)
g.drawString("Dolly",50,10);
}

What will be the result when you attempt to compile and run the program?
1) The string "Dolly" will be displayed at the centre oI the Irame
2) An error at compilation complaining at the signature oI the paint method
3) The lower part oI the word Dolly will be seen at the top oI the Irame, with the top
hidden.
4) The string "Dolly" will be shown at the bottom oI the Irame.


Question 49)
What will be the result when you attempt to compile this program?
public class Rand
public static void main(String argv||)
int iRand;
iRand Math.random();
System.out.println(iRand);
}
}
1) Compile time error reIerring to a cast problem
2) A random number between 1 and 10
3) A random number between 0 and 1
4) A compile time error about random being an unrecognised method


Question 50)
Given the Iollowing code
import java.io.*;
public class Th
public static void main(String argv||)
Th t new Th();
t.amethod();
}
public void amethod()
try
ioCall();
}catch(IOException ioe)}
}

}
What code would be most likely Ior the body oI the ioCall method
1) public void ioCall ()throws IOException
DataInputStream din new DataInputStream(System.in);
din.readChar();
}
2) public void ioCall ()throw IOException
DataInputStream din new DataInputStream(System.in);
din.readChar();
}
3) public void ioCall ()
DataInputStream din new DataInputStream(System.in);
din.readChar();
}
4) public void ioCall throws IOException()
DataInputStream din new DataInputStream(System.in);
din.readChar();
}


Question 51)
What will happen when you compile and run the Iollowing code?
public class Scope
private int i;
public static void main(String argv||)
Scope s new Scope();
s.amethod();
}//End oI main
public static void amethod()
System.out.println(i);
}//end oI amethod
}//End oI class
1) A value oI 0 will be printed out
2) Nothing will be printed out
3) A compile time error
4) A compile time error complaining oI the scope oI the variable i


Question 52)

You want to lay out a set oI buttons horizontally but with more space between the Iirst
button and the rest. You are going to use the GridBagLayout manager to control the way
the buttons are set out. How will you modiIy the way the GridBagLayout acts in order to
change the spacing around the Iirst button?
1) Create an instance oI the GridBagConstraints class, call the weightx() method and then
pass the GridBagConstraints instance with the component to the setConstraints method oI
the GridBagLayout class.
2) Create an instance oI the GridBagConstraints class, set the weightx Iield and then pass
the GridBagConstraints instance with the component to the setConstraints method oI the
GridBagLayout class.
3) Create an instance oI the GridBagLayout class, set the weightx Iield and then call the
setConstraints method oI the GridBagLayoutClass with the component as a parameter.
4) Create an instance oI the GridBagLayout class, call the setWeightx() method and then
pass the GridBagConstraints instance with the component to the setConstraints method oI
the GridBagLayout class.


Question 53)

Which oI the Iollowing can you perIorm using the File class?
1) Change the current directory
2) Return the name oI the parent directory
3) Delete a Iile
4) Find iI a Iile contains text or binary inIormation


Question 54)
Which oI the Iollowing code Iragments will compile without error
1)
public void paint(Graphics g)
int polyX|| 20,150,150};
int polyY|| 20,20,120};
g.drawPolygon(polyX, polyY,3);
}
2)
public void paint(Graphics g)
int polyX|| 20,150,150};
int polyY|| 20,20,120};
g.drawPolygon(polyX, polyY);
}
3)
public void paint(Graphics g)
int polyX|3| 20,150,150};
int polyY|3| 20,20,120};
g.drawPolygon(polyX, polyY,3);
}
4)
public void paint(Graphics g)
int polyX|| 20,150,150};
int polyY|| 20,20,120};
drawPolygon(polyX, polyY);
}


Question 55)
You are concerned that your program may attempt to use more memory than is available.
To avoid this situation you want to ensure that the Java Virtual Machine will run its
garbage collection just beIore you start a complex routine. What can you do to be certain
that garbage collection will run when you want .
1) You cannot be certain when garbage collection will run
2) Use the Runtime.gc() method to Iorce garbage collection
3) Ensure that all the variables you require to be garbage collected are set to null
4) Use the System.gc() method to Iorce garbage collection


Question 56)
You are using the GridBagLayout manager to place a series oI buttons on a Frame. You
want to make the size oI one oI the buttons bigger than the text it contains. Which oI the
Iollowing will allow you to do that?
1) The GridBagLayout manager does not allow you to do this
2) The setFill method oI the GridBagLayout class
3) The setFill method oI the GridBagConstraints class
4) The Iill Iield oI the GridBagConstraints class


Question 57)
Which oI the Iollowing most closely describes a bitset collection?
1) A class that contains groups oI unique sequences oI bits
2) A method Ior Ilipping individual bits in instance oI a primitive type
3) An array oI boolean primitives that indicate zeros or ones
4) A collection Ior storing bits as on-oII inIormation, like a vector oI bits


Question 58)

You have these Iiles in the same directory. What will happen when you attempt to
compile and run Class1.java iI you have not already compiled Base.java
//Base.java
package Base;
class Base
protected void amethod()
System.out.println("amethod");
}//End oI amethod
}//End oI class base
package Class1;
//Class1.java
public class Class1 extends Base

public static void main(String argv||)
Base b new Base();
b.amethod();
}//End oI main
}//End oI Class1
1) Compile Error: Methods in Base not Iound
2) Compile Error: Unable to access protected method in base class
3) Compilation Iollowed by the output "amethod"
4)Compile error: Superclass Class1.Base oI class Class1.Class1 not Iound


Question 59)
What will happen when you attempt to compile and run the Iollowing code
class Base
private void amethod(int iBase)
System.out.println("Base.amethod");
}
}

class Over extends Base


public static void main(String argv||)
Over o new Over();
int iBase0;
o.amethod(iBase);
}
public void amethod(int iOver)
System.out.println("Over.amethod");
}

}
1) Compile time error complaining that Base.amethod is private
2) Runtime error complaining that Base.amethod is private
3) Output oI "Base.amethod"
4) Output oI "Over.amethod"


Question 60)
You are creating an applet with a Frame that contains buttons. You are using the
GridBagLayout manager and you have added Four buttons. At the moment the buttons
appear in the centre oI the Irame Irom leIt to right. You want them to appear one on top
oI the other going down the screen. What is the most appropriate way to do this.
1) Set the gridy value oI the GridBagConstraint class to a value increasing Irom 1 to 4
2) set the Iill value oI the GridBagConstraint class to VERTICAL
3) Set the ipady value oI the GridBagConstraint class to a value increasing Irom 0 to 4
4) Set the Iill value oI the GridBagLayout class to GridBag.VERTICAL



Answers

Answer 1)

Objective 4.5)
5) int i10;
explanation:
1) Iloat I1.3;
Will not compile because the deIault type oI a number with a Iloating point component is
a double. This would compile with a cast as in
Iloat I(Iloat) 1.3
2) char c"a";
Will not compile because a char (16 bit unsigned integer) must be deIined with single
quotes. This would compile iI it were in the Iorm
char c'a';
3) byte b257;
Will not compile because a byte is eight bits. Take oI one bit Ior the sign component you
can deIine numbers between
-128 to 127
4) a boolean value can either be true oI Ialse, null is not allowed.

Answer 2)

Objective 4.1
1) Can't make static reIerence to void amethod.
Because main is deIined as static you need to create an instance oI the class in order to
call any non-static methods. Thus a typical way to do this would be.
MyClass mnew MyClass();
m.amethod();
Answer 2 is an attempt to conIuse because the convention is Ior a main method to be in
the Iorm
String argv||
That argv is just a convention and any acceptable identiIier Ior a string array can be used.
Answers 3 and 4 are just nonsense.

Answer 3)

Objective 4.1)
2 and 3 will compile without error.
1 will not compile because any package declaration must come beIore any other code.
Comments may appear anywhere.

Answer 4)

Objective 4.5)
1) A byte is a signed 8 bit integer.

Answer 5)

Objective 4.2)
4) Exception raised: "java.lang.ArrayIndexOutOIBoundsException: 2"
Unlike C/C java does not start the parameter count with the program name. It does
however start Irom zero. So in this case zero starts with good, morning would be 1 and
there is no parameter 2 so an exception is raised.

Answer 6)

Objective 1.5)
1) iI
3) goto
4) while
5) case
then is not a Java keyword, though iI you are Irom a VB background you might think it
was. Goto is a reserved word in Java.

Answer 7)

Objective 1.10)
2) variable2
3) whatavariable
4) 3
5) $anothervar
An identiIier can begin with a letter (most common) or a dollar sign($) or an
underscore(). An identiIier cannot start with anything else such as a number, a hash, # or
a dash -. An identiIier cannot have a dash in its body, but it may have an underscore .
Choice 4) 3 looks strange but it is an acceptable, iI unwise Iorm Ior an identiIier.

Answer 8)

Objective 1.6)
4) 0
Class level variables are always initialised to deIault values. In the case oI an int this will
be 0. Method level variables are not given deIault values and iI you attempt to use one
beIore it has been initialised it will cause the
Error Variable i may not have been initialized
type oI error.

Answer 9)

Objective 1.7,3.4)
3 ) 2
No error will be triggered.
Like in C/C, arrays are always reIerenced Irom 0. Java allows an array to be populated
at creation time. The size oI array is taken Irom the number oI initializers. II you put a
size within any oI the square brackets you will get an error.

Answer 10)

Objective 1.7)
3) 0
Arrays are always initialised when they are created. As this is an array oI ints it will be
initalised with zeros.

Answer 11)

Objective 3.6
3) Error Mine must be declared abstract
A class that contains an abstract method must itselI be declared as abstract. It may
however contain non abstract methods. Any class derived Irom an abstract class must
either deIine all oI the abstract methods or be declared abstract itselI.

Answer 12)

Objective 4.1)
3) one, two, deIault
Code will continue to Iall through a case statement until it encounters a break.

Answer 13)

Objective 4.1)
2) deIault, zero
Although it is normally placed last the deIault statement does not have to be the last item
as you Iall through the case block. Because there is no case label Iound matching the
expression the deIault label is executed and the code continues to Iall through until it
encounters a break.

Answer 14)

Objective 4.2,
2,3
Example 1 will not compile because iI must always test a boolean. This can catch out
C/C programmers who expect the test to be Ior either 0 or not 0.

Answer 15)

Objective 4.5)
3) No such Iile Iound, doing Iinally, -1
The no such Iile Iound message is to be expected, however you can get caught out iI you
are not aware that the Iinally clause is almost always executed, even iI there is a return
statement.

Answer 16)

Objective

1) Methods cannot be overriden to be more private
Static methods cannot be overriden but they can be overloaded. There is no logic or
reason why private methods should not be overloaded. Option 4 is a jumbled up version
oI the limitations oI exceptions Ior overriden methods

Answer 17)

Objective 5.8 (sort oI)
3) Runtime Exception
Without the cast to sub you would get a compile time error. The cast tells the compiler
that you really mean to do this and the actual type oI b does not get resolved until
runtime. Casting down the object hierarchy as the compiler cannot be sure what has been
implemented in descendent classes. Casting up is not a problem because sub classes will
have the Ieatures oI the base classes. This can Ieel counter intuitive iI you are aware that
with primitives casting is allowed Ior widening operations (ie byte to int).

Answer 18)

Objective unknown
3) null
II a parameter is not available the applet will still run, but any attempt to access the
parameter will return a null.

Answer 19)

Objective 1.1)
3) Move up the hierarchy in the HTML documentation to locate methods in base
classes
The documentation created by JavaDoc is based on tags placed into the sourcecode. The
convention Ior documentation is that methods and Iields oI ancestors are not duplicated
in sub classes. So iI you are looking Ior something and it does not appear to be there, you
move up the class hierarchy to Iind it.

Answer 20)

Objective 10.4)
3) One button occupying the entire Irame saying Bye
The deIault layout manager Ior a Frame is a border layout. II directions are not given (ie
North, South, East or West), any button will simply go in the centre and occupy all the
space. An additional button will simply be placed over the previous button. What you
would probably want in a real example is to set up a Ilow layout as in
setLayout(new FlowLayout());

Which would allow the buttons to both appear side by side, given the appropriate Iont
and size.
Applets and panels have a deIault FlowLayout manager


Answer 21)

Objective 4.4)
1,2
Value Ior i1 Value Ior j1
Value Ior i2 Value Ior j1
The statement continue outer causes the code to jump to the label outer and the Ior loop
increments to the next number.

Answer 22)

Objective 9.5)
3) An arc bounded by a box oI height 50, width 50, with a top leIt at coordinates oI 45,
90, starting at 90 degrees and traversing through 180 degrees counter clockwise.
IillArc(int x, int y, int width, int height, int startDegrees, int arcDegrees)
The IillArc Iunction draws an arc in a box with a top leIt at coordinates X & Y.
II the ArcDegrees is a positive number the arc is drawn counter clockwise.

Answer 23)

Objective 4.7)
2,3
Options 1, & 4 will not compile as they attempt to throw Exceptions not declared in the
base class. Because options 2 and 4 take a parameter oI type long they represent
overloading not overriding and there is no such limitations on overloaded methods.

Answer 24)

Objective 8.1)
3) System.out.println(Math.ceil(-4.7));
Options 1 and 2 will produce -5 and option 4 will not compile because the min method
requires 2 parameters.

Answer 25)

Objective 2.2
3) Error: Cant convert java lang Integer
The wrapper classes cannot be used like primitives.
Wrapper classes have similar names to primitives but all start with upper case letters.
Thus in this case we have int as a primitive and Integer as a wrapper. The objectives do
not speciIically mention the wrapper classes but don't be surprised iI they come up.

Answer 26)

Objective 8.2)
2) ic
This is a bit oI a catch question. Anyone with a C/C background would Iigure out that
addressing in strings starts with 0 so that 1 corresponds to i in the string Bicycle. The
catch is that the second parameter returns the endcharacter minus 1. In this case it means
instead oI the "icy" being returned as intuition would expect it is only "ic".

Answer 27)

Objective 8.2)
3) s.indexOI('v');
charAt returns the letter at the position rather than searching Ior a letter and returning the
position, MID is just to conIuse the Basic Programmers, indexOI(s,'v'); is how some
Iuture VB/J nightmare hybrid, might perIorm such a calculation.

Answer 28)
Objective 2.2

1) s3s1 s2;
Java does not allow operator overloading as in C, but Ior the sake oI convenience the
operator is overridden Ior strings.

Answer 29)

Objective 2.5)
4) 7
The , is known as the Or operator, you could think oI it as the either/or operator. Turning
the numbers into binary gives
4100
3011
For each position, iI either number contains a 1 the result will contain a result in that
position. As every position contains a 1 the result will be
111
Which is decimal 7.

Answer 30)

Objective 3.7)
1,2,3
public, private, static are all legal access modiIiers Ior this inner class.

Answer 31)

Objective 9.6)
Opening an image Iile requires an Image object, The Image class has no constructor that
takes the name oI an image Iile . For an application (rather than an applet) an image is
created using the Toolkit class as in option 2.
2) Image imageToolkit.getDeIaultToolkit().getImage("MyPicture.jpg");

Answer 32)

Objective 1.3)
2) setLayout(new GridLayout(2,2));
Changing the layout manager is the same Ior an Applet or an application. Answer 1 is
wrong though it might have been a reasonable name Ior the designers to choose. Answers
3 and 4 are incorrect because changing the layout manager always requires an instance oI
one oI the Layout Managers and these are bogus methods.
Instead oI creating the anonymous instance oI the Layout manager as in option 2 you can
also create a named instance and pass that as a parameter. This is oIten what automatic
code generators such as Borland/Inprise JBuilder do.

Answer 33)

Objective 7.2)
3) The code will cause an error at compile time
The error is caused because run should have a void not an int return type.
Any class that is implements an interIace must create a method to match all oI the
methods in the interIace. The Runnable interIace has one method called run that has a
void return type.The sun compiler gives the error
Method redeIined with diIIerent return type: int run() was deIined as void run();

Answer 34)

Objective 11.1)
2) public void update(Graphics g)
paint(g);
}
II not overridden the update method clears the background and calls paint(); By
overriding the update method, any previously drawn graphics will not be cleared. This is
only a trivial way oI preserving any graphics drawn. II the application is resized or the
drawing area covered in some way the graphics will be cleared.

Answer 35)

Objective 2.2
4) Compile time error
The only operator overloading oIIered by java is the sign Ior the String class. A char is
a 16 bit integer and cannot be concatenated to a string with the operator.

Answer 36)

Objective 8.2)
3) iI(s.equalsIgnoreCase(s2))
String comparison is case sensitive so using the equals string method will not return a
match. Using theoperator just compares where memory address oI the reIerences and
noCaseMatch was just something I made up to give me a Iourth slightly plausible option.

Answer 37)

Objective 9.1)
1) s.setBackground(Color.pink);
For speakers oI the more British spelt English note that there is no letter u in Color. Also
the constants Ior colors are in lower case.

Answer 38)

Objective 13.1)
4) The File class does not support directly changing the current directory.
This seems rather surprising to me, as changing the current directory is a very common
requirement. You may be able to get around this limitation by creating a new instance oI
the File class passing the new directory to the constructor as the path name.

Answer 39)

Objective 9.2)
1)With a Iixed Iont you will see 5 characters, with a proportional it will depend on the
width oI the characters
With a proportional Iont the letter w will occupy more space than the letter i. So iI you
have all wide characters you may have to scroll to the right to see the entire text oI a
TextField.

Answer 40)

Objective 5.8
3) On the line AIter //Two put super(10);
Constructors can only be invoked Irom within constructors.

Answer 41)

Objective 2.8)
3) 10 and 40
when a parameter is passed to a method the method receives a copy oI the value. The
method can modiIy its value without aIIecting the original copy. Thus in this example
when the value is printed out the method has not changed the value.

Answer 42)

Objective 3.3
4) Ior(int i0; i ia.length;i)
Although you could control the looping with a literal number as with the number 4 used
in option 3, it is better practice to use the length property oI an array. This provides
against bugs that might result iI the size oI the array changes. This question also checks
that you know that arrays starts Irom zero and not One as option 3 starts Irom one.
Remember that array length is a Iield and not a Iunction like the string size method.

Answer 43)

Objective 3.6 (maybe)
1) Error at compile time
This is a slightly sneaky one as it looks like a question about constructors, but it is
attempting to test knowledge oI the use oI the private modiIier. A top level class cannot
be deIined as private. II you didn't notice the modiIier private, remember in the exam to
be real careIul to read every part oI the question.

Answer 44)

Objective 1.11)
3)10
The name oI the class might give you a clue with this question, Oct Ior Octal. PreIixing a
number with a zero indicates that it is in Octal Iormat. Thus when printed out it gets
converted to base ten. 012 in octal means the Iirst column Irom the right has a value oI 2
and the next along has a value oI one times eight. In decimal that adds up to 10.

Answer 45)

Objective 3.5)
1) Error at compile time
The variable i is created at the level oI amethod and will not be available inside the
method multi.

Answer 46)

Java2 Objective 10.1)
1) Set
The Set interIace ensures that its elements are unique, but does not order the elements. In
reality you probably wouldn't create your own class using the Set interIace. You would
be more likely to use one oI the JDK classes that use the Set interIace such as ArraySet.

Answer 47)

Java2 Objective 10.1)
4) Vector vnew Vector(100);
v.addElement("99")
A vector can only store objects not primitives. The parameter "99" Ior the addElement
method pases a string object to the Vector. Option 1) creates a vector OK but then uses
array syntax to attempt to assign a primitive. Option 2 also creates a vector then uses
correct Vector syntax but Ialls over when the parameter is a primitive instead oI an
object.

Answer 48)
Objective 9.5)

3) The lower part oI the word Dolly will be seen at the top oI the Iorm
The Second parameter to the drawstring method indicates where the baseline oI the string
will be placed. Thus the 3rd parameter oI 10 indicates the Y coordinate to be 10 pixels
Irom the top oI the Frame. This will result in just the bottom oI the string Dolly showing
up or possibly only the descending part oI the letter y.

Answer 49)

Objective 8.1)
1) Compile time error reIerring to a cast problem
This is a bit oI a sneaky one as the Math.random method returns a pseudo random
number between 0 and 1, and thus option 3 is a plausible Answer. However the number
returned is a double and so the compiler will complain that a cast is needed to convert a
double to an int.

Answer 50)
Objective 4.6)

1) public void ioCall ()throws IOException
DataInputStream din new DataInputStream(System.in);
din.readChar();
}
II a method might throw an exception it must either be caught within the method with a
try/catch block, or the method must indicate the exception to any calling method by use
oI the throws statement in its declaration. Without this, an error will occur at compile
time.

Answer 51)
Objective 3.10)

3) A compile time error
Because only one instance oI a static method exists not matter how many instance oI the
class exists it cannot access any non static variables. The JVM cannot know which
instance oI the variable to access. Thus you will get an error saying something like

Can't make a static reIerence to a non static variable

Answer 52)
Java2 Objective 8.2)

2) Create an instance oI the GridBagConstraints class, set the weightx Iield and then pass
the GridBagConstraints instance with the component to the setConstraints method oI the
GridBagLayout class.
The Key to using the GridBagLayout manager is the GridBagConstraint class. This class
is not consistent with the general naming conventions in the java API as you would
expect that weightx would be set with a method, whereas it is a simple Iield (variable).



Answer 53)
Objective 13.1)

2) Return the name oI the parent directory
3) Delete a Iile
It is surprising that you can't change the current directory. It is not so surprising that you
can't tell iI a Iile contains text or binary inIormation.

Answer 54)
Objective 9.5)

1)
public void paint(Graphics g)
int polyX|| 20,150,150};
int polyY|| 20,20,120};
g.drawPolygon(polyX, polyY,3);
}
drawPolygon takes three parameters, the Iirst two are arrays oI the X,Y coordinates and
the Iinal is an integer speciIying the number oI vertices (whatever they are).

Answer 55)
Objective 6.1)

1) You cannot be certain when garbage collection will run
Although there is a Runtime.gc(), this only suggests that the Java Virtual Machine does
its garbage collection. You can never be certain when the garbage collector will run.
Roberts and Heller is more speciIic abou this than Boone. This uncertainty can cause
consternation Ior C programmers who wish to run Iinalize methods with the same
intent as they use destructor methods.

Answer 56)
Java2 Objective 8.2)

4) The Iill Iield oI the GridBagConstraints class
Unlike the GridLayout manager you can set the individual size oI a control such as a
button using the GridBagLayout manager. A little background knowledge would indicate
that it should be controlled by a setSomethingOrOther method, but it isn't.


Answer 57)
Java2 Objective 10.1)
)
4) A collection Ior storing bits as on-oII inIormation, like a vector oI bits
This is the description given to a bitset in Bruce Eckels "Thinking in Java" book. The
reIerence to unique sequence oI bits was an attempt to mislead because oI the use oI the
word Set in the name bitset. Normally something called a set implies uniqueness oI the
members, but not in this context.

Answer 58)

Objective 3.10)
4)Compile error: Superclass Class1.Base oI class Class1.Class1 not Iound
Using the package statement has an eIIect similar to placing a source Iile into a diIIerent
directory. Because the Iiles are in diIIerent packages they cannot see each other. The stuII
about File1 not having been compiled was just to mislead, java has the equivalent oI an
"automake", whereby iI it was not Ior the package statements the other Iile would have
been automatically compiled.

Answer 59)

Objective 5.3)
4) Output oI Over.amethod()
The names oI parameters to an overridden method is not important.

Answer 60)
Java2 Objective 8.2)
1) Set the gridy value oI the GridBagConstraint class to a value increasing Irom 1 to 4
Answer 4 is Iairly obviously bogus as it is the GridBagConstraint class that does most oI
the magic in laying out components under the GridBagLayout manager. The Iill value oI
the GridBagConstraint class controls the behavior inside its virtual cell and the ipady
Iield controls the internal padding around a component.


Cracked By Charitra Choudhary, INDIA
Any Help, Plz Feel Free to mail (Charitra.choudharyrediIImail.com)
MCSE, MCSE, CCNA, Comptia A, N, JCP, MCAD, MCSD, MVP


Questions

Question 1)
What will happen when you attempt to compile and run this code?
abstract class Base
abstract public void myIunc();
public void another()
System.out.println("Another method");
}
}
public class Abs extends Base
public static void main(String argv||)
Abs a new Abs();
a.amethod();
}
public void myIunc()
System.out.println("My Iunc");
}
public void amethod()
myIunc();

}
}
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain that the Base class has non abstract methods
3) The code will compile but complain at run time that the Base class has non abstract
methods
4) The compiler will complain that the method myIunc in the base class has no body,
nobody at all to looove it



Question 2)

What will happen when you attempt to compile and run this code?
public class MyMain
public static void main(String argv)
System.out.println("Hello cruel world");
}
}
1) The compiler will complain that main is a reserved word and cannot be used Ior a class
2) The code will compile and when run will print out "Hello cruel world"
3) The code will compile but will complain at run time that no constructor is deIined
4) The code will compile but will complain at run time that main is not correctly deIined


Question 3)
Which oI the Iollowing are Java modiIiers?

1) public
2) private
3) Iriendly
4) transient
4) vagrant


Question 4)
What will happen when you attempt to compile and run this code?
class Base
abstract public void myIunc();
public void another()
System.out.println("Another method");
}
}
public class Abs extends Base
public static void main(String argv||)
Abs a new Abs();
a.amethod();
}
public void myIunc()
System.out.println("My Iunc");
}
public void amethod()
myIunc();

}
}
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain that the Base class is not declared as abstract.
3) The code will compile but complain at run time that the Base class has non abstract
methods
4) The compiler will complain that the method myIunc in the base class has no body,
nobody at all to looove it


Question 5)
Why might you deIine a method as native?
1) To get to access hardware that Java does not know about
2) To deIine a new data type such as an unsigned integer
3) To write optimised code Ior perIormance in a language such as C/C
4) To overcome the limitation oI the private scope oI a method


Question 6)
What will happen when you attempt to compile and run this code?
class Base
public Iinal void amethod()
System.out.println("amethod");
}
}
public class Fin extends Base
public static void main(String argv||)
Base b new Base();
b.amethod();
}
}
1) Compile time error indicating that a class with any Iinal methods must be declared
Iinal itselI
2) Compile time error indicating that you cannot inherit Irom a class with Iinal methods
3) Run time error indicating that Base is not deIined as Iinal
4) Success in compilation and output oI "amethod" at run time.


7) What will happen when you attempt to compile and run this code?
public class Mod
public static void main(String argv||)
}
public static native void amethod();
}
1) Error at compilation: native method cannot be static
2) Error at compilation native method must return value
3) Compilation but error at run time unless you have made code containing native
amethod available
4) Compilation and execution without error


8) What will happen when you attempt to compile and run this code?
private class Base}
public class Vis
transient int iVal;
public static void main(String elephant||)
}
}
1)Compile time error: Base cannot be private
2)Compile time error indicating that an integer cannot be transient
3)Compile time error transient not a data type
4)Compile time error malIormed main method



9) What happens when you attempt to compile and run these two Iiles in the same
directory?
//File P1.java
package MyPackage;
class P1
void aIancymethod()
System.out.println("What a Iancy method");
}
}
//File P2.java
public class P2 extends P1
aIancymethod();
}
1) Both compile and P2 outputs "What a Iancy method" when run
2) Neither will compile
3) Both compile but P2 has an error at run time
4) P1 compiles cleanly but P2 has an error at compile time


10) You want to Iind out the value oI the last element oI an array. You write the
Iollowing code. What will happen when you compile and run it.?
public class MyAr
public static void main(String argv||)
int|| i new int|5|;
System.out.println(i|5|);
}
}
1) An error at compile time
2) An error at run time
3) The value 0 will be output
4) The string "null" will be output


11) You want to loop through an array and stop when you come to the last element.
Being a good java programmer and Iorgetting everything you ever knew about C/C
you know that arrays contain inIormation about their size. Which oI the Iollowing can
you use?

1)myarray.length();
2)myarray.length;
3)myarray.size
4)myarray.size();


Question 12)
What best describes the appearance oI an application with the Iollowing code?
import java.awt.*;

public class FlowAp extends Frame

public static void main(String argv||)
FlowAp Ianew FlowAp();
Ia.setSize(400,300);
Ia.setVisible(true);
}
FlowAp()
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"));
add(new Button("Four"));
}//End oI constructor

}//End oI Application
1) A Frame with buttons marked One to Four placed on each edge.
2) A Frame with buutons marked One to Iour running Irom the top to bottom
3) A Frame with one large button marked Four in the Centre
4) An Error at run time indicating you have not set a LayoutManager


Question 13)
How do you indicate where a component will be positioned using Flowlayout?
1) North, South,East,West
2) Assign a row/column grid reIerence
3) Pass a X/Y percentage parameter to the add method
4) Do nothing, the FlowLayout will position the component



Question 14)
How do you change the current layout manager Ior a container
1) Use the setLayout method
2) Once created you cannot change the current layout manager oI a component
3) Use the setLayoutManager method
4) Use the updateLayout method


Question 15)
Which oI the Iollowing are Iields oI the GridBagConstraints class?
1) ipadx
2) Iill
3) insets
4) width


Question 16)
What most closely matches the appearance when this code runs?
import java.awt.*;

public class CompLay extends Frame
public static void main(String argv||)
CompLay cl new CompLay();
}

CompLay()
Panel p new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
add("South",p);
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
1) The buttons will run Irom leIt to right along the bottom oI the Frame
2) The buttons will run Irom leIt to right along the top oI the Irame
3) The buttons will not be displayed
4) Only button three will show occupying all oI the Irame


Question 17)
Which statements are correct about the anchor Iield?
1) It is a Iield oI the GridBagLayout manager Ior controlling component placement
2) It is a Iield oI the GridBagConstraints class Ior controlling component placement
3) A valid setting Ior the anchor Iield is GridBagConstraints.NORTH
4) The anchor Iield controls the height oI components added to a container


Question 18)
What will happen when you attempt to compile and run the Iollowing code?
public class Bground extends Thread

public static void main(String argv||)
Bground b new Bground();
b.run();
}
public void start()
Ior (int i 0; i 10; i)
System.out.println("Value oI i " i);
}
}

}
1) A compile time error indicating that no run method is deIined Ior the Thread class
2) A run time error indicating that no run method is deIined Ior the Thread class
3) Clean compile and at run time the values 0 to 9 are printed out
4) Clean compile but no output at runtime


Question 19)
10)When using the GridBagLayout manager, each new component requires a new
instance oI the GridBagConstraints class. Is this statement
1) true
2) Ialse


Question 20)
Which most closely matches a description oI a Java Map?
1) A vector oI arrays Ior a 2D geographic representation
2) A class Ior containing unique array elements
3) A class Ior containing unique vector elements
4) An interIace that ensures that implementing classes cannot contain duplicate keys


Question 21)
How does the set collection deal with duplicate elements?
1) An exception is thrown iI you attempt to add an element with a duplicate value
2) The add method returns Ialse iI you attempt to add an element with a duplicate value
3) A set may contain elements that return duplicate values Irom a call to the equals
method
4) Duplicate values will cause an error at compile time


Question 22)
What can cause a thread to stop executing?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread's stop method.
4) A call to the halt method oI the Thread class


Question 23)
For a class deIined inside a method, what rule governs access to the variables oI the
enclosing method?
1) The class can access any variable
2) The class can only access static variables
3) The class can only access transient variables
4) The class can only access Iinal variables


Question 24)

Under what circumstances might you use the yield method oI the Thread class
1) To call Irom the currently running thread to allow another thread oI the same priority
to run
2) To call on a waiting thread to allow it to run
3) To allow a thread oI higher priority to run
4) To call Irom the currently running thread with a parameter designating which thread
should be allowed to run


Question 25)
What will happen when you attempt to compile and run the Iollowing code
public class Hope
public static void main(String argv||)
Hope h new Hope();
}
protected Hope()
Ior(int i 0; i 10; i )
System.out.println(i);
}
}
}
1) Compilation error: Constructors cannot be declared protected
2) Run time error: Constructors cannot be declared protected
3) Compilation and running with output 0 to 10
4) Compilation and running with output 0 to 9


Question 26)
What will happen when you attempt to compile and run the Iollowing code
public class MySwitch

public static void main(String argv||)
MySwitch ms new MySwitch();
ms.amethod();
}

public void amethod()

int k10;
switch(k)
deIault: //Put the deIault at the bottom, not here
System.out.println("This is the deIault output");
break;
case 10:
System.out.println("ten");
case 20:
System.out.println("twenty");
break;
}
}
}
1) None oI these options
2) Compile time errror target oI switch must be an integral type
3) Compile and run with output "This is the deIault output"
4) Compile and run with output "ten"


Question 27)
Which oI the Iollowing is the correct syntax Ior suggesting that the JVM perIorms
garbage collection
1) System.Iree();
2) System.setGarbageCollection();
3) System.out.gc();
4) System.gc();


Question 28)

What will happen when you attempt to compile and run the Iollowing code
public class As
int i 10;
int j;
char z 1;
boolean b;
public static void main(String argv||)
As a new As();
a.amethod();
}
public void amethod()
System.out.println(j);
System.out.println(b);
}
}
1) Compilation succeeds and at run time an output oI 0 and Ialse
2) Compilation succeeds and at run time an output oI 0 and true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value


Question 29)

What will happen when you attempt to compile and run the Iollowing code with the
command line "hello there"
public class Arg
String|| MyArg;
public static void main(String argv||)
MyArgargv;
}
public void amethod()
System.out.println(argv|1|);
}
}
1) Compile time error
2) Compilation and output oI "hello"
3) Compilation and output oI "there"
4) None oI the above


Question 30)
What will happen when you attempt to compile and run the Iollowing code
public class StrEq

public static void main(String argv||)
StrEq s new StrEq();
}
private StrEq()
String s "Marcus";
String s2 new String("Marcus");
iI(s s2)
System.out.println("we have a match");
}else
System.out.println("Not equal");
}
}
}
1) Compile time error caused by private constructor
2) Output oI "we have a match"
3) Output oI "Not equal"
4) Compile time error by attempting to compare strings using


Question 31)
1) What will happen when you attempt to compile and run the Iollowing code
import java.io.*;

class Base
public static void amethod()throws FileNotFoundException}
}

public class ExcepDemo extends Base
public static void main(String argv||)
ExcepDemo e new ExcepDemo();
}
public static void amethod()}

protected ExcepDemo()
try
DataInputStream din new DataInputStream(System.in);
System.out.println("Pausing");
din.readChar();
System.out.println("Continuing");
this.amethod();
}catch(IOException ioe) }
}

}
1)Compile time error caused by protected constructor
2) Compile time error caused by amethod not declaring Exception
3) Runtime error caused by amethod not declaring Exception
4) Compile and run with output oI "Pausing" and "Continuing" aIter a key is hit



Question 32)

What will happen when you attempt to compile and run this program
public class Outer
public String name "Outer";
public static void main(String argv||)
Inner i new Inner();
i.showName();
}//End oI main

private class Inner
String name new String("Inner");
void showName()
System.out.println(name);
}
}//End oI Inner class

}
1) Compile and run with output oI "Outer"
2) Compile and run with output oI "Inner"
3) Compile time error because Inner is declared as private
4) Compile time error because oI the line creating the instance oI Inner


Question 33)
What will happen when you attempt to compile and run this code
//Demonstration oI event handling
import java.awt.event.*;
import java.awt.*;

public class MyWc extends Frame implements WindowListener
public static void main(String argv||)
MyWc mwc new MyWc();
}
public void windowClosing(WindowEvent we)
System.exit(0);
}//End oI windowClosing

public void MyWc()
setSize(300,300);
setVisible(true);
}
}//End oI class
1) Error at compile time
2) Visible Frame created that that can be closed
3) Compilation but no output at run time
4) Error at compile time because oI comment beIore import statements


Question 34)
Which option most Iully describes will happen when you attempt to compile and run the
Iollowing code
public class MyAr
public static void main(String argv||)
MyAr m new MyAr();
m.amethod();
}
public void amethod()
static int i;
System.out.println(i);
}
}
1) Compilation and output oI the value 0
2) Compile time error because i has not been initialized
3) Compilation and output oI null
4) Compile time error


Question 35)
Which oI the Iollowing will compile correctly
1) short myshort 99S;
2) String name 'Excellent tutorial Mr Green';
3) char c 17c;
4)int z 015;


Question 36)
Which oI the Iollowing are Java key words
1)double
2)Switch
3)then
4)instanceoI


Question 37
What will be output by the Iollowing line?
System.out.println(Math.Iloor(-2.1));
1) -2
2) 2.0
3) -3
4) -3.0


Question 38)
Given the Iollowing main method in a class called Cycle and a command line oI
java Cycle one two
what will be output?
public static void main(String bicycle||)
System.out.println(bicycle|0|);
}
1) None oI these options
2) cycle
3) one
4) two


Question 39)
Which oI the Iollowing statements are true?
1) At the root oI the collection hierarchy is a class called Collection
2) The collection interIace contains a method called enumerator
3) The interator method returns an instance oI the Vector class
4) The set interIace is designed Ior unique elements


Question 40)
Which oI the Iollowing statements are correct?
1) II multiple listeners are added to a component only events Ior the last listener added
will be processed
2) II multiple listeners are added to a component the events will be processed Ior all but
with no guarantee in the order
3) Adding multiple listeners to a comnponent will cause a compile time error
4) You may remove as well add listeners to a component.


Question 41)
Given the Iollowing code
class Base}

public class MyCast extends Base
static boolean b1Ialse;
static int i -1;
static double d 10.1;

public static void main(String argv||)
MyCast m new MyCast();
Base b new Base();
//Here
}
}
Which oI the Iollowing, iI inserted at the comment //Here will allow the code to compile
and run without error

1) bm;
2) mb;
3) d i;
4) b1 i;


Question 42)
Which oI the Iollowing statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in a class that extends
Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword
synchronized
4) Thread scheduling algorithms are platIorm dependent


Question 43)
Your chieI SoItware designer has shown you a sketch oI the new Computer parts system
she is about to create. At the top oI the hierarchy is a Class called Computer and under
this are two child classes. One is called LinuxPC and one is called WindowsPC. The
main diIIerence between the two is that one runs the Linux operating System and the
other runs the Windows System (oI course another diIIerence is that one needs constant
re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one
called Server and one Called Workstation. How might you appraise your designers work?

1) Give the goahead Ior Iurther design using the current scheme
2) Ask Ior a re-design oI the hierarchy with changing the Operating System to a Iield
rather than Class type
3) Ask Ior the option oI WindowsPC to be removed as it will soon be obsolete
4) Change the hierarchy to remove the need Ior the superIluous Computer Class.



Question 44)
Objective 4.1)
Which oI the Iollowing statements are true
1) An inner class may be deIined as static
2) There are NO circumstances where an inner class may be deIined as private
3) An anonymous class may have only one constructor
4) An inner class may extend another class


Question 45)
What will happen when you attempt to compile and run the Iollowing code
int Output10;
boolean b1 Ialse;
iI((b1true) && ((Output10)20))
System.out.println("We are equal "Output);
}else

System.out.println("Not equal! "Output);
}
1) Compile error, attempting to peIorm binary comparison on logical data type
2) Compilation and output oI "We are equal 10"
3) Compilation and output oI "Not equal! 20"
4) Compilation and output oI "Not equal! 10"


Question 46)
Given the Iollowing variables which oI the Iollowing lines will compile without error?
String s "Hello";
long l 99;
double d 1.11;
int i 1;
int j 0;
1) j i s;
2) j ij;
3) jid;
4)jil;


Question 47)
What will be output by the Iollowing line oI code?
System.out.println(010,4);
1) 14
2) 0
3) 6
4) 12


Question 48)
Given the Iollowing variables
char c 'c';
int i 10;
double d 10;
long l 1;
String s "Hello";
Which oI the Iollowing will compile without error?
1)cci;
2)si;
3)is;
4)cs;


Question 49)
Which oI the Iollowing will compile without error?
1) File I new File("/","autoexec.bat");
2) DataInputStream d new DataInputStream(System.in);
3) OutputStreamWriter o new OutputStreamWriter(System.out);
4) RandomAccessFile r new RandomAccessFile("OutFile");


Question 50)
Given the Iolowing classes which oI the Iollowing will compile without error?
interIace IFace}
class CFace implements IFace}
class Base}

public class ObReI extends Base
public static void main(String argv||)
ObReI ob new ObReI();
Base b new Base();
Object o1 new Object();
IFace o2 new CFace();
}
}
1)o1o2;
2)bob;
3)obb;
4)o1b;


Question 51)
Given the Iollowing code what will be the output?
class ValHold
public int i 10;
}
public class ObParm
public static void main(String argv||)
ObParm o new ObParm();
o.amethod();
}
public void amethod()
int i 99;
ValHold v new ValHold();
v.i30;
another(v,i);
System.out.println(v.i);

}//End oI amethod

public void another(ValHold v, int i)
i0;
v.i 20;
ValHold vh new ValHold();
v vh;
System.out.println(v.i " "i);
}//End oI another
}
1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20


Question 52)
Given the Iollowing class deIinition, which oI the Iollowing methods could be legally
placed aIter the comment
//Here
public class Rid
public void amethod(int i, String s)}
//Here
}
1)public void amethod(String s, int i)}
2)public int amethod(int i, String s)}
3)public void amethod(int i, String mystring)}
4) public void Amethod(int i, String s) }


Question 53)
Given the Iollowing class deIinition which oI the Iollowing can be legally placed aIter the
comment line
//Here ?
class Base
public Base(int i)}
}

public class MyOver extends Base
public static void main(String arg||)
MyOver m new MyOver(10);
}
MyOver(int i)
super(i);
}
MyOver(String s, int i)
this(i);
//Here

}
}
1)MyOver m new MyOver();
2)super();
3)this("Hello",10);
4)Base b new Base(10);


Question 54)
Given the Iollowing class deIinition, which oI the Iollowing statements would be legal
aIter the comment //Here
class InOut
String s new String("Between");


public void amethod(Iinal int iArgs)
int iam;
class Bicycle
public void sayHello()
//Here
}//End oI bicycle class
}
}//End oI amethod
public void another()
int iOther;
}
}
1)System.out.println(s);
2) System.out.println(iOther);
3) System.out.println(iam);
4) System.out.println(iArgs);



Question 55)
Which oI the Iollowing are methods oI the Thread class?
1) yield()
2) sleep(long msec)
3) go()
4) stop()


Question 56)
Which oI the Iollowing methods are members oI the Vector class and allow you to input
a new element
1) addElement
2) insert
3) append
4) addItem


Question 57)
Which oI the Iollowing statements are true?
1) Adding more classes via import statements will cause a perIormance overhead, only
import classes you actually use.
2) Under no circumstances can a class be deIined with the private modiIier
3) A inner class may under some circumstances be deIined with the protected modiIier
4) An interIace cannot be instantiated


Question 58)
Which oI the Iollowing are correct event handling methods

1) mousePressed(MouseEvent e)}
2) MousePressed(MouseClick e)}
3) IunctionKey(KeyPress k)}
4) componentAdded(ContainerEvent e)}



Question 59)
Which oI the Iollowing are methods oI the Collection interIace?
1) iterator
2) isEmpty
3) toArray
4) setText


Question 60)
Which oI the Iollowing best describes the use oI the synhronized keyword?
1) Allows two process to run in paralell but to communicate with each other
2) Ensures only one thread at a time may access a class or object
3) Ensures that two or more processes will start and end at the same time
4) Ensures that two or more Threads will start and end at the same time

Answers

Answer 1)
Objective 1.2)
1) The code will compile and run, printing out the words "My Func"
A class that contains an abstract method must be declared abstract itselI, but may contain
non abstract methods.

Answer 2)
Objective 4.1)
4) The code will compile but will complain at run time that main is not correctly deIined
In this example the parameter is a string not a string array as needed Ior the correct main
method

Answer 3)
Objective 4.3)
1) public
2) private
4) transient
The keyword transient is easy to Iorget as is not Irequently used. Although a method may
be considered to be Iriendly like in C it is not a Java keyword.

Answer 4)
Objective 1.2)
2) The compiler will complain that the Base class is not declared as abstract.
II a class contains abstract methods it must itselI be declared as abstract

Answer 5)
Objective 1.2)
1) To get to access hardware that Java does not know about
3) To write optimised code Ior perIormance in a language such as C/C

Answer 6)
Objective 1.2)
4) Success in compilation and output oI "amethod" at run time.
A Iinal method cannot be ovverriden in a sub class, but apart Irom that it does not cause
any other restrictions.

Answer 7)
Objective 1.2)
4) Compilation and execution without error
It would cause a run time error iI you had a call to amethod though.

Answer 8)
Objective 1.2)
1)Compile time error: Base cannot be private
A top leve (non nested) class cannot be private.

Answer 9)
Objective 1.2)
4) P1 compiles cleanly but P2 has an error at compile time
The package statement in P1.java is the equivalent oI placing the Iile in a diIIerent
directory to the Iile P2.java and thus when the compiler tries to compile P2 an error
occurs indicating that superclass P1 cannot be Iound.

Answer 10)
Objective 1.1)
2) An error at run time
This code will compile, but at run-time you will get an ArrayIndexOutOIBounds
exception. This becuase counting in Java starts Irom 0 and so the 5th element oI this
array would be i|4|.
Remember that arrays will always be initialized to deIault values wherever they are
created.

Answer 11)
Objective 1.1)
2)myarray.length;
The String class has a length() method to return the number oI characters. I have
sometimes become conIused between the two.

Answer 12)
Objective 8.2)
3) A Frame with one large button marked Four in the Centre
The deIault layout manager Ior a Frame is the BorderLayout manager. This Layout
manager deIaults to placing components in the centre iI no constraint is passed with the
call to the add method.

Answer 13)
Objective 8.2)
4) Do nothing, the FlowLayout will position the component

Answer 14)
Objective 8.2)
1) Use the setLayout method

Answer 15)
Objective 8.2)
1) ipadx
2) Iill
3) insets

Answer 16)
Objective 8.2)
2) The buttons will run Irom leIt to right along the top oI the Irame

The call to the setLayout(new FlowLayout()) resets the Layout manager Ior the entire
Irame and so the buttons end up at the top rather than the bottom.

Answer 17)
Objective 8.2)
2) It is a Iield oI the GridBagConstraints class Ior controlling component placement
3) A valid settting Ior the anchor Iield is GridBagconstraints.NORTH

Answer 18)
Objective 7.1)
4) Clean compile but no output at runtime

This is a bit oI a sneaky one as I have swapped around the names oI the methods you
need to deIine and call when running a thread. II the Ior loop were deIined in a method
called
public void run()
and the call in the main method had been to b.start()
The list oI values Irom 0 to 9 would have been output.


Answer 19)
Objective 8.2)
2) Ialse

You can re-use the same instance oI the GridBagConstraints when added successive
components.

Answer 20)
Objective 10.1)
4) An interIace that ensures that implementing classes cannot contain duplicates

Answer 21)
Objective 10.1)
2) The add method returns Ialse iI you attempt to add an element with a duplicate value
I Iind it a surprise that you do not get an exception.


Answer 22)
Objective 7.1)
1) The program exits via a call to exit(0);
2) The priority oI another thread is increased
3) A call to the stop method oI the Thread class

Java threads are somewhat platIorm dependent and you should be careIull when making
assumptions about Thread priorities. On some platIorms you may Iind that a Thread with
higher priorities gets to "hog" the processor.

Answer 23)
Objective 4.1)
4) The class can only access Iinal variables

Answer 24)
Objective 7.1)

1) To call Irom the currently running thread to allow another thread oI the same priority
to run

Answer 25)
Objective 6.2)

4) Compilation and running with output 0 to 9

Answer 26)
Objective 2.1)
1) None oI these options

Because oI the lack oI a break statement aIter the break 10; statement the actual output
will be

"ten" Iollowed by "twenty"

Answer 27)
Objective 3.1)
4) System.gc();

Answer 28)
Objective 4.4)
1) Compilation succeeds and at run time an output oI 0 and Ialse
The deIault value Ior a boolean declared at class level is Ialse, and integer is 0;

Answer 29)
Objective 1.2)
1) Compile time error
You will get an error saying something like "Cant make a static reIerence to a non static
variable". Note that the main method is static.

Answer 30)
Objective 5.2)
3) Output oI "Not equal"
Despite the actual character strings matching, using the operator will simply compare
memory location. Because the one string was created with the new operator it will be in a
diIIerent location in memory to the other string.

Answer 31)
Objective 2.3)
4) Compile and run with output oI "Pausing" and "Continuing" aIter a key is hit
An overriden method in a sub class must not throw Exceptions not thrown in the base
class. In the case oI the method amethod it throws no exceptions and will thus compile
without complain. There is no reason that a constructor cannot be protected.

Answer 32)
Objective 6.3)
4) Compile time error because oI the line creating the instance oI Inner

This looks like a question about inner classes but it is also a reIerence to the Iact that the
main method is static and thus you cannot directly access a non static method. The line
causing the error could be Iixed by changing it to say
Inner i new Outer().new Inner();
Then the code would compile and run producing the output "Inner"

Answer 33)
Objective 4.6)
1) Error at compile time
II you implement an interIace you must create bodies Ior all methods in that interIace.
This code will produce an error saying that MyWc must be declared abstract because it
does not deIine all oI the methods in WindowListener. Option 4 is nonsense as comments
can appear anywhere. Option 3 suggesting that it might compile but not produce output is
ment to mislead on the basis that what looks like a constructor is actually an ordinary
method as it has a return type.

Answer 34)
Objective 1.2)
4) Compile time error
An error will be caused by attempting to deIine an integer as static within a method. The
liIetime oI a Iield within a method is the duration oI the running oI the method. A static
Iield exists once only Ior the class. An approach like this does work with Visual Basic.

Answer 35)
Objective 9.5)
4)int z 015;
The letters c and s do not exist as literal indicators and a String must be enclosed with
double quotes, not single as in this case.

Answer 36)
Objective 4.3)
1)double
4)instanceoI

Note the upper case S on switch means it is not a keyword and the word then is part oI
Visual Basic but not Java. Also, instanceoI looks like a method but is actually a keyword,

Answer 37)
Objective 9.2)
4) -3.0

Answer 38)
Objective 4.2)
3) one
Command line parameters start Irom 0 and Iromt he Iirst parameter aIter the name oI the
compile (normally Java)

Answer 39)
Objective 10.1)
4) The set is designed Ior unique elements.
Collection is an interIace, not a class. The Collection interIace includes a method called
iterator. This returns an instance oI the Iterator class which has some similarities with
Enumerators.
The name set should give away the purpose oI the Set interIace as it is analogous to the
Set concept in relational databases which implies uniquness.

Answer 40)
Objective 8.1)
2) II multiple listeners are added to a component the events will be processed Ior all but
with no guarantee in the order
4) You may remove as well add listeners to a component.
It ought to be Iairly intuitive that a component ought to be able to have multiple listeners.
AIter all, a text Iield might want to respond to both the mouse and keyboard

Answer 41)
Objective 5.1)
1) bm;
3) d i;
You can assign up the inheritance tree Irom a child to a parent but not the other way
without an explicit casting. A boolean can only ever be assigned a boolean value.

Answer 42)
Objective 7.3)
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword
synchronized
4) Thread scheduling algorithms are platIorm dependent
Yes that says dependent and not independent.

Answer 43)
Objective 6.1)
2) Ask Ior a re-design oI the hierarchy with changing the Operating System to a Iield
rather than Class type
OI course there are as many ways to design an object hierarchy as ways to pronounce
Bjarne Strousjoup, but this is the sort oI answer that Sun will proabably be looking Ior in
the exam.

Answer 44)
Objective 4.1)
1) An inner class may be deIined as static
4) An inner class may extend another class
A static inner class is also sometimes known as a top level nested class. There is some
debate iI such a class should be called an inner class. I tend to think it should be on the
basis that it is created inside the opening braces oI another class. How could an
anonymous class have a constructor?. Remember a constructor is a method with no return
type and the same name as the class. Inner classes may be deIined as private

Answer 45)
Objective 5.3)
4) Compilation and output oI "Not equal! 10"
The output will be "Not equal 10". This illustrates that the Output 10 calculation was
never perIormed because processing stopped aIter the Iirst operand was evaluated to be
Ialse. II you change the value oI b1 to true processing occurs as you would expect and the
output is "We are equal 20";.

Answer 46)
Objective 5.1)
2)j ij;
4)jil;

Answer 47)
Objective 5.3)
4) 12
As well as the binary OR objective this questions requires you to understand the octal
notaction which means that the leading letter zero (not the letter O)) means that the Iirst 1
indicates the number contains one eight and nothing else. Thus this calculation in decimal
mean
8,4
To convert this to binary means
1000
0100
----
1100
----
Which is 12 in decimal
The , bitwise operator means that Ior each position where there is a 1, results in a 1 in the
same position in the answer.

Answer 48)
Objective 5.1)
2)si;
Only a String acts as iI the operator were overloaded

Answer 49)
Objective 10.1)
Although the objectives do not speciIically mention the need to understand the I/O
Classes, Ieedback Irom people who have taken the exam indicate that you will get
questions on this topic. As you will probably need to know this in the real world oI Java
programming, get Iamiliar with the basics. I have assigned these questions to Objective
10.1 as that is a Iairly vague objective.
1) File I new File("/","autoexec.bat");
2) DataInputStream d new DataInputStream(System.in);
3) OutputStreamWriter o new OutputStreamWriter(System.out);
Option 4, with the RandomAccess Iile will not compile because the constructor must also
be passed a mode parameter which must be either "r" or "rw"

Answer 50)
Objective 5.1)
1)o1o2;
2)bob;
4)o1b;

Answer 51)
Objective 5.4)
4) 10,0,20
In the call
another(v,i);
A reIerence to v is passed and thus any changes will be intact aIter this call.

Answer 52)
Objective 6.2)
1) public void amethod(String s, int i)}
4) public void Amethod(int i, String s) }
Overloaded methods are diIIerentiated only on the number, type and order oI parameters,
not on the return type oI the method or the names oI the parameters.

Answer 53)
Objective 6.2)

4)Base b new Base(10);
Any call to this or super must be the Iirst line in a constructor. As the method already has
a call to this, no more can be inserted.

Answer 54)
Objective 4.1)
1)System.out.println(s);
4) System.out.println(iArgs);
A class within a method can only see Iinal variables oI the enclosing method. However it
the normal visibility rules apply Ior variables outside the enclosing method.

Answer 55)
Objective 7.2)
1) yield()
2) sleep
4) stop()
Note, the methods stop and suspend have been deprecated with the Java2 release, and you
may get questions on the exam that expect you to know this. Check out the Java2 Docs
Ior an explanation

Answer 56)
Objective 10.1)
1) addElement

Answer 57)
Objective 4.1)
The import statement allows you to use a class directly instead oI Iully qualiIying it with
the Iull package name, adding more classess with the import statement does not cause a
runtime perIormance overhad. An inner class can be deIined with the private modiIier.
3) An inner class can be deIined with the protected modiIier
4) An interIace cannot be instantiated

Answer 58)
Objective 4.6)
1) mousePressed(MouseEvent e)}
4) componentAdded(ContainerEvent e)}

Answer 59)
Objective 10.1)
1) iterator
2) isEmpty
3) toArray

Answer 60)
Objective 7.3)
2) Ensures only one thread at a time may access a class or object



Cracked By Charitra Choudhary, INDIA
Any Help, Plz Feel Free to mail (Charitra.choudharyrediIImail.com)
MCSE, MCSE, CCNA, Comptia A, N, JCP, MCAD, MCSD, MVP


Q. 1
Which colour is used to indicate instance methods in the standard "javadoc" Iormat
documentation:
blue
red
purple
orange
Select the most appropriate answer.
Q. 2
What is the correct ordering Ior the import, class and package declarations when Iound in
a single Iile?
package, import, class
class, import, package
import, package, class
package, class, import
Select the most appropriate answer.
Q. 3
Which methods can be legally applied to a string object?
equals(String)
equals(Object)
trim()
round()
toString()
Select all correct answers.
Q. 4
What is the parameter speciIication Ior the public static void main method?
String args ||
String || args
Strings args ||
String args
Select all correct answers.
Q. 5
What does the zeroth element oI the string array passed to the public static void main
method contain?
The name oI the program
The number oI arguments
The Iirst argument iI one is present
Select the most appropriate answer.
Q. 6
Which oI the Iollowing are Java keywords?
goto
malloc
extends
FALSE
Select all correct answers
Q. 7
What will be the result oI compiling the Iollowing code:
public class Test
public static void main (String args ||)
int age;
age age 1;
System.out.println("The age is " age);
}
}
Compiles and runs with no output
Compiles and runs printing out The age is 1
Compiles but generates a runtime error
Does not compile
Compiles but generates a compile time error
Select the most appropriate answer.
Q. 8
Which oI these is the correct Iormat to use to create the literal char value a?
a`
"a"
new Character(a)
\000a
Select the most appropriate answer.
Q. 9
What is the legal range oI a byte integral type?
0 - 65, 535
(128) 127
(32,768) 32,767
(256) 255
Select the most appropriate answer.
Q. 10
Which oI the Iollowing is illegal:
int i 32;
Iloat I 45.0;
double d 45.0;
Select the most appropriate answer.
Q. 11
What will be the result oI compiling the Iollowing code:
public class Test
static int age;
public static void main (String args ||)
age age 1;
System.out.println("The age is " age);
}
}
Compiles and runs with no output
Compiles and runs printing out The age is 1
Compiles but generates a runtime error
Does not compile
Compiles but generates a compile time error
Select the most appropriate answer.
Q. 12
Which oI the Iollowing are correct?
128 ~~ 1 gives 64
128 ~~~ 1 gives 64
128 ~~ 1 gives 64
128 ~~~ 1 gives 64
Select all correct answers
Q. 13
Which oI the Iollowing return true?
"john" "john"
"john".equals("john")
"john" "john"
"john".equals(new Button("john"))
Select all correct answers.
Q. 14
Which oI the Iollowing do not lead to a runtime error?
"john" " was " " here"
"john" 3
3 5
5 5.5
Select all correct answers.
Q. 15
Which oI the Iollowing are so called "short circuit" logical operators?
&
,,
&&
,
Select all correct answers.
Q. 16
Which oI the Iollowing are acceptable?
Object o new Button("A");
Boolean Ilag true;
Panel p new Frame();
Frame I new Panel();
Panel p new Applet();
Select all correct answers.
Q. 17
What is the result oI compiling and running the Iollowing code:
public class Test
static int total 10;
public static void main (String args ||)
new Test();
}
public Test ()
System.out.println("In test");
System.out.println(this);
int temp this.total;
iI (temp ~ 5)
System.out.println(temp);
}
}
}
The class will not compile
The compiler reports and error at line 2
The compiler reports an error at line 9
The value 10 is one oI the elements printed to the standard output
The class compiles but generates a runtime error
Select all correct answers.
Q 18
Which oI the Iollowing is correct:
String temp || new String "j" "a" "z"};
String temp || "j " " b" "c"};
String temp "a", "b", "c"};
String temp || "a", "b", "c"};
Select the most appropriate answer.
Q. 19
What is the correct declaration oI an abstract method that is intended to be public:
public abstract void add();
public abstract void add() }
public abstract add();
public virtual add();
Select the most appropriate answer.
Q. 20
Under what situations do you obtain a deIault constructor?
When you deIine any class
When the class has no other constructors
When you deIine at least one constructor
Select the most appropriate answer.
Q. 21
Given the Iollowing code:
public class Test
.
}
Which oI the Iollowing can be used to deIine a constructor Ior this class:
public void Test() .}
public Test() .}
public static Test() .}
public static void Test() .}
Select the most appropriate answer.
Q. 22
Which oI the Iollowing are acceptable to the Java compiler:
iI (2 3) System.out.println("Hi");
iI (2 3) System.out.println("Hi");
iI (true) System.out.println("Hi");
iI (2 ! 3) System.out.println("Hi");
iI (aString.equals("hello")) System.out.println("Hi");
Select all correct answers.
Q. 23
Assuming a method contains code which may raise an Exception (but not a
RuntimeException), what is the correct way Ior a method to indicate that it expects the
caller to handle that exception:
throw Exception
throws Exception
new Exception
Don't need to speciIy anything
Select the most appropriate answer.
Q. 24
What is the result oI executing the Iollowing code, using the parameters 4 and 0:
public void divide(int a, int b)
try
int c a / b;
} catch (Exception e)
System.out.print("Exception ");
} Iinally
System.out.println("Finally");
}
Prints out: Exception Finally
Prints out: Finally
Prints out: Exception
No output
Select the most appropriate answer.
Q.25
Which oI the Iollowing is a legal return type oI a method overloading the Iollowing
method:
public void add(int a) .}
void
int
Can be anything
Select the most appropriate answer.
Q.26
Which oI the Iollowing statements is correct Ior a method which is overriding the
Iollowing method:
public void add(int a) .}
the overriding method must return void
the overriding method must return int
the overriding method can return whatever it likes
Select the most appropriate answer.
Q. 27
Given the Iollowing classes deIined in separate Iiles:
class Vehicle
public void drive()
System.out.println("Vehicle: drive");
}
}
class Car extends Vehicle
public void drive()
System.out.println("Car: drive");
}
}
public class Test
public static void main (String args ||)
Vehicle v;
Car c;
v new Vehicle();
c new Car();
v.drive();
c.drive();
v c;
v.drive();
}
}
What will be the eIIect oI compiling and running this class Test?
Generates a Compiler error on the statement v c;
Generates runtime error on the statement v c;
Prints out:
Vehicle: drive
Car: drive
Car: drive
Prints out:
Vehicle: drive
Car: drive
Vehicle: drive
Select the most appropriate answer.
Q. 28
Where in a constructor, can you place a call to a constructor deIined in the super class?
Anywhere
The Iirst statement in the constructor
The last statement in the constructor
You can't call super in a constructor
Select the most appropriate answer.
Q. 29
Which variables can an inner class access Irom the class which encapsulates it?
All static variables
All Iinal variables
All instance variables
Only Iinal instance variables
Only Iinal static variables
Select all correct answers.
Q. 30
What class must an inner class extend:
The top level class
The Object class
Any class or interIace
It must extend an interIace
Select the most appropriate answer.
Q. 31
In the Iollowing code, which is the earliest statement, where the object originally held in
e, may be garbage collected:
public class Test
public static void main (String args ||)
Employee e new Employee("Bob", 48);
e.calculatePay();
System.out.println(e.printDetails());
e null;
e new Employee("Denise", 36);
e.calculatePay();
System.out.println(e.printDetails());
}
}
Line 10
Line 11
Line 7
Line 8
Never
Select the most appropriate answer.
Q. 32
What is the name oI the interIace that can be used to deIine a class that can execute
within its own thread?
Runnable
Run
Threadable
Thread
Executable
Select the most appropriate answer.
Q. 33
What is the name oI the method used to schedule a thread Ior execution?
init();
start();
run();
resume();
sleep();
Select the most appropriate answer.
Q. 34
Which methods may cause a thread to stop executing?
sleep();
stop();
yield();
wait();
notiIy();
notiIyAll()
synchronized()
Select all correct answers.
Q. 35
Write code to create a text Iield able to display 10 characters (assuming a Iixed size Iont)
displaying the initial string "hello":
:
Q. 36
Which oI the Iollowing methods are deIined on the Graphics class:
drawLine(int, int, int, int)
drawImage(Image, int, int, ImageObserver)
drawString(String, int, int)
add(Component);
setVisible(boolean);
setLayout(Object);
Select all correct answers.
Q. 37
Which oI the Iollowing layout managers honours the preIerred size oI a component:
CardLayout
FlowLayout
BorderLayout
GridLayout
Select all correct answers.
Q. 38
Given the Iollowing code what is the eIIect oI a being 5:
public class Test
public void add(int a)
loop: Ior (int i 1; i 3; i)
Ior (int j 1; j 3; j)
iI (a 5)
break loop;
}
System.out.println(i * j);
}
}
}
}
Generate a runtime error
Throw an ArrayIndexOutOIBoundsException
Print the values: 1, 2, 2, 4
Produces no output
Select the most appropriate answer.
Q. 39
What is the eIIect oI issuing a wait() method on an object
II a notiIy() method has already been sent to that object then it has no eIIect
The object issuing the call to wait() will halt until another object sends a notiIy() or
notiIyAll() method
An exception will be raised
The object issuing the call to wait() will be automatically synchronized with any other
objects using the receiving object.
Select the most appropriate answer.
Q. 40
The layout oI a container can be altered using which oI the Iollowing methods:
setLayout(aLayoutManager);
addLayout(aLayoutManager);
layout(aLayoutManager);
setLayoutManager(aLayoutManager);
Select all correct answers.
Q. 41
Using a FlowLayout manager, which is the correct way to add elements to a container:
add(component);
add("Center", component);
add(x, y, component);
set(component);
Select the most appropriate answer.
Q. 42
Given that a Button can generate an ActionEvent which listener would you expect to
have to implement, in a class which would handle this event?
FocusListener
ComponentListener
WindowListener
ActionListener
ItemListener
Select the most appropriate answer.
Q. 43
Which oI the Iollowing, are valid return types, Ior listener methods:
boolean
the type oI event handled
void
Component
Select the most appropriate answer.
Q. 44
Assuming we have a class which implements the ActionListener interIace, which method
should be used to register this with a Button?
addListener(*);
addActionListener(*);
addButtonListener(*);
setListener(*);
Select the most appropriate answer.
Q. 45
In order to cause the paint(Graphics) method to execute, which oI the Iollowing is the
most appropriate method to call:
paint()
repaint()
paint(Graphics)
update(Graphics)
None you should never cause paint(Graphics) to execute
Select the most appropriate answer.
Q. 46
Which oI the Iollowing illustrates the correct way to pass a parameter into an applet:
applet codeTest.class age33 width100 height100~
param nameage value33~
applet codeTest.class nameage value33 width100 height100~
applet Test 33~
Select the most appropriate answer.
Q. 47
Which oI the Iollowing correctly illustrate how an InputStreamReader can be created:
new InputStreamReader(new FileInputStream("data"));
new InputStreamReader(new FileReader("data"));
new InputStreamReader(new BuIIeredReader("data"));
new InputStreamReader("data");
new InputStreamReader(System.in);
Select all correct answers.
Q. 48
What is the permanent eIIect on the Iile system oI writing data to a new
FileWriter("report"), given the Iile report already exists?
The data is appended to the Iile
The Iile is replaced with a new Iile
An exception is raised as the Iile already exists
The data is written to random locations within the Iile
Select the most appropriate answer.
Q. 49
What is the eIIect oI adding the sixth element to a vector created in the Iollowing manner:
new Vector(5, 10);
An IndexOutOIBounds exception is raised.
The vector grows in size to a capacity oI 10 elements
The vector grows in size to a capacity oI 15 elements
Nothing, the vector will have grown when the IiIth element was added
Select the most appropriate answer.
Q. 50
What is the result oI executing the Iollowing code when the value oI x is 2:
switch (x)
case 1:
System.out.println(1);
case 2:
case 3:
System.out.println(3);
case 4:
System.out.println(4);
}
Nothing is printed out
The value 3 is printed out
The values 3 and 4 are printed out
The values 1, 3 and 4 are printed out
Select the most appropriate answer.
Q. 51
Consider the Iollowing example:
class First
public First (String s)
System.out.println(s);
}
}
public class Second extends First
public static void main(String args ||)
new Second();
}
}
What is the result oI compiling and running the Second class?
Nothing happens
A string is printed to the standard out
An instance oI the class First is generated
An instance oI the class Second is created
An exception is raised at runtime stating that there is no null parameter constructor in
class First.
The class second will not compile as there is no null parameter constructor in the class
First
Select the most appropriate answer.
Q. 52 What is the result oI executing the Iollowing Iragment oI code:
boolean Ilag Ialse;
iI (Ilag true)
System.out.println("true");
} else
System.out.println("Ialse");
}
true is printed to standard out
Ialse is printed to standard out
An exception is raised
Nothing happens
Select the most appropriate answer.
Q. 53
Consider the Iollowing classes:
public class Test
public static void test()
this.print();
}
public static void print()
System.out.println("Test");
}
public static void main(String args ||)
test();
}
}
What is the result oI compiling and running this class?
The string Test is printed to the standard out.
A runtime exception is raised stating that an object has not been created.
Nothing is printed to the standard output.
An exception is raised stating that the method test cannot be Iound.
An exception is raised stating that the variable this can only be used within an instance.
The class Iails to compile stating that the variable this is undeIined.
Select all correct answers.
Q. 54
Examine the Iollowing class deIinition:
public class Test
public static void test()
print();
}
public static void print()
System.out.println("Test");
}
public void print()
System.out.println("Another Test");
}
}
What is the result oI compiling this class:
A successIul compilation.
A warning stating that the class has no main method.
An error stating that there is a duplicated method.
An error stating that the method test() will call one or other oI the print() methods.
Select the most appropriate answer.
Q. 55
What is the result oI compiling and executing the Iollowing Java class:
public class ThreadTest extends Thread
public void run()
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}
public static void main(String args ||)
(new ThreadTest()).start();
}
}
Compilation will Iail in the method main.
Compilation will Iail in the method run.
A warning will be generated Ior method run.
The string "In run" will be printed to standard out.
Both strings will be printed to standard out.
Nothing will happen.
Select the most appropriate answer.
Q. 56
Given the Iollowing sequence oI Java statements
StringBuIIer sb new StringBuIIer("abc");
String s new String("abc");
sb.append("deI");
s.append("deI");
sb.insert(1, "zzz");
s.concat(sb);
s.trim();
Which oI the Iollowing statements are true:
The compiler would generate an error Ior line 1.
The compiler would generate an error Ior line 2.
The compiler would generate an error Ior line 3.
The compiler would generate an error Ior line 4.
The compiler would generate an error Ior line 5.
The compiler would generate an error Ior line 6.
The compiler would generate an error Ior line 7.
Select all correct answers.
Q. 57
What is the result oI executing the Iollowing Java class:
import java.awt.*;
public class FrameTest extends Frame
public FrameTest()
add (new Button("First"));
add (new Button("Second"));
add (new Button("Third"));
pack();
setVisible(true);
}
public static void main(String args ||)
new FrameTest();
}
}
Select Irom the Iollowing options:
Nothing happens.
Three buttons are displayed across a window.
A runtime exception is generated (no layout manager speciIied).
Only the "Iirst" button is displayed.
Only the "second" button is displayed.
Only the "third" button is displayed.
Select the most appropriate answer.
Q. 58
Consider the Iollowing tags and attributes oI tags:
CODEBASE
ALT
NAME
CLASS
JAVAC
HORIZONTALSPACE
VERTICALSPACE
WIDTH
PARAM
JAR
Which oI the above can be used within the APPLET~ and /APPLET~ tags?
line 1, 2, 3
line 2, 5, 6, 7
line 3, 4, 5
line 8, 9, 10
line 8, 9
Select all correct answers.
Q. 59
Which oI the Iollowing is a legal way to construct a RandomAccessFile:
RandomAccessFile("data", "r");
RandomAccessFile("r", "data");
RandomAccessFile("data", "read");
RandomAccessFile("read", "data");
Select the most appropriate answer.
Q. 60
CareIully examine the Iollowing code:
public class StaticTest
static
System.out.println("Hi there");
}
public void print()
System.out.println("Hello");
}
public static void main(String args ||)
StaticTest st1 new StaticTest();
st1.print();
StaticTest st2 new StaticTest();
st2.print();
}
}
When will the string "Hi there" be printed?
Never.
Each time a new instance is created.
Once when the class is Iirst loaded into the Java virtual machine.
Only when the static method is called explicitly.
Select the most appropriate answer.
Q. 61
Consider the Iollowing program:
public class Test public static void main (String args ||) boolean a Ialse; iI (a true)
System.out.println("Hello");
Else
System.out.println("Goodbye");
}
}
What is the result:
A. Program produces no output but terminates correctly.
B. Program does not terminate.
C. Prints out "Hello"
D. Prints out "Goodbye"
Select the most appropriate answer.
Q. 62
Examine the Iollowing code which includes an inner class:
public Iinal class Test4 implements A
class Inner
void test()
iI (Test4.this.Ilag);
sample();
}
}
}
private boolean Ilag Ialse;
public void sample()
System.out.println("Sample");
}
public Test4()
(new Inner()).test();
}
public static void main(String args ||)
new Test4();
}
}
What is the result:
A. Prints out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
Select the most appropriate answer.
Q. 63
CareIully examine the Iollowing class:
public class Test5 public static void main (String args ||) /* This is the start oI a
comment
iI (true)
Test5 new test5();
System.out.println("Done the test");
}
/* This is another comment */
System.out.println ("The end");
}
}
What is the result:
A. Prints out "Done the test" and nothing else.
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile.
E. The program generates a runtime exception.
F. The program prints out "The end" and nothing else.
G. The program prints out "Done the test" and "The end"
Select the most appropriate answer.
Q. 64
The Iollowing code deIines a simple applet:
import java.applet.Applet;
import java.awt.*;
public class Sample extends Applet
private String text "Hello World";
public void init()
add(new Label(text));
}
public Sample (String string)
text string;
}
}
It is accessed Iorm the Iollowing HTML page:
html~
title~Sample Applet/title~
body~
applet code"Sample.class" width200 height200~/applet~
/body~
/html~
What is the result oI compiling and running this applet:
A. Prints "Hello World".
B. Generates a runtime error.
C. Does nothing.
D. Generates a compile time error.
Select the most appropriate answer.
Q. 65
Examine the Iollowing code:
public class Calc
public static void main (String args ||)
int total 0;
Ior (int i 0, j 10; total ~ 30; i, --j)
System.out.println(" i " i " : j " j);
total (i j);
}
System.out.println("Total " total);
}
}
Does this code:
A. Produce a runtime error
B. Produce a compile time error
C. Print out "Total 0"
D. Generate the Iollowing as output:
i 0 : j 10
i 1 : j 9
i 2 : j 8
Total 30
Please select the most appropriate answer.

Answers to Java CertiIication Mock Exam
1. B 2. A 3. A, B, C, E 4. A, B 5. C
6. A, C 7. D 8. A 9. B 10. B
11. B 12. A,B 13. A, B 14. A, B, C, D 15.B, C
16. A, E 17. D 18. D 19. A 20. B
21. B 22. A, C, D, E 23. B 24. A 25. C
26. A 27. C 28. B 29. A, B, C 30. C
31. C 32. A 33. B 34. A, B, C, D 35. new TextField("hello", 10)
36. A, B, C 37. B 38. D 39. B 40. A
41. A 42. D 43. C 44. B 45. B
46. B 47. A, E 48. B 49. C 50. C
51. F 52. A 53. F 54. C 55. D
56. D, F 57. F 58. A, E 59. A 60. C
61. C 62. A 63. F 64. B 65. C



Cracked By Charitra Choudhary, INDIA
Any Help, Plz Feel Free to mail (Charitra.choudharyrediIImail.com)
MCSE, MCSE, CCNA, Comptia A, N, JCP, MCAD, MCSD, MVP


Questions

Q 1. What is the output oI the Iollowing
StringBuIIer sb1 new StringBuIIer("Amit");
StringBuIIer sb2 new StringBuIIer("Amit");
String ss1 "Amit";
System.out.println(sb1sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
Ans:
a) Ialse
Ialse
Ialse
dar
b) Ialse
true
Ialse
Poddar
c) Compiler Error
d) true
true
Ialse
dar




***** Look careIully at code and answer the Iollowing questions ( Q2 to Q8)
1 import java.applet.Applet;
2 import java.awt.*;
3 import java.awt.event.*;
4 public class hello4 extends Applet
5 public void init()
6 add(new myButton("BBB"));
7 }
8 public void paint(Graphics screen)
9 }
10 class myButton extends Button
11 myButton(String label)
12 super(label);
13 }
14 public String paramString()
15 return super.paramString();
16 }
17 }
18 public static void main(String|| args)
19 Frame myFrame new Frame(
20 "Copyright Amit");
21 myFrame.setSize(300,100);
22 Applet myApplet new hello4();
23 Button b new Button("My Button");
24 myApplet.add(b);
25 b.setLabel(b.getLabel()"New");
26 // myButton b1 (new hello4()).new myButton("PARAMBUTTON");
27 System.out.println(b1.paramString());
28 myFrame.add(myApplet);
29 myFrame.setVisible(true);
30 myFrame.addWindowListener(new WindowAdapter()
31 public void windowClosing(WindowEvent e)
32 System.exit(0);}});
33 }
34 } //End hello4 class.
Q2. II you run the above program via appletviewer ( deIining a HTML Iile), You see on
screen.
a) Two buttons
b) One button with label as "BBB"
c) One button with label as "My ButtonNew"
d) One button with label as "My Button"


Q3. In the above code iI line 26 is uncommented and program runs as standalone
application
a) Compile Error
b) Run time error
c) It will print the the label as PARAMBUTTON Ior button b1

Q4 In the code iI you compile as "javac hello4.java" Iollowing Iiles will be generated.
a) hello4.class, myButton.class,hello41.class
b)hello4.class, hello4$myButton.class,hello4$1.class
c)hello4.clas,hello4$myButton.class

Q5. II above program is run as a standalone application. How many buttons will be
displayed
a) Two buttons
b) One button with label as "BBB"
c) One button with label as "My ButtonNew"
d) One button with label as "My Button"

Q6. II Irom line no 14 keyword "public" is removed, what will happen.( Hint
:paramString() method in java.awt.Button is a protected method. (Assume line 26 is
uncommented)
a) Code will not compile.
b) Code will compile but will give a run time error.
c) Code will compile and no run time error.

Q7. II Irom line no 14 keyword "public" is replaced with "protected", what will
happen.(Hint :paramString() method in java.awt.Button is a protected method.(Assume
line 26 is uncommented)
a) Code will not compile.
b) Code will compile but will give a run time error.
c) Code will compile and no run time error.

Q8.II line no 26 is replaced with Button b1 new Button("PARAMBUTTON").(Hint
:paramString() method in java.awt.Button is a protected method.(Assume line 26 is
uncommented)
a) Code will not compile.
b) Code will compile but will give a run time error.
c) Code will compile and no run time error.

Q9. What is the output oI Iollowing iI the return value is "the value 0 iI the argument
string is equal to this string; a value less than 0 iI this string is lexicographically less than
the string argument; and a value greater than 0 iI this string is lexicographically greater
than the string argument" (Assuming written inside main)
String s5 "AMIT";
String s6 "amit";
System.out.println(s5.compareTo(s6));
System.out.println(s6.compareTo(s5));
System.out.println(s6.compareTo(s6));
Ans
a~ -32
32
0
b~ 32
32
0
c~ 32
-32
0
d~ 0
0
0

Q 10) What is the output (Assuming written inside main)
String s1 new String("amit");
String s2 s1.replace('m','i');
s1.concat("Poddar");
System.out.println(s1);
System.out.println((s1s2).charAt(5));
a) Compile error
b) amitPoddar
o
c) amitPoddar
i
d) amit
i

Q 11) What is the output (Assuming written inside main)
String s1 new String("amit");
System.out.println(s1.replace('m','r'));
System.out.println(s1);
String s3"arit";
String s4"arit";
String s2 s1.replace('m','r');
System.out.println(s2s3);
System.out.println(s3s4);
a) arit
amit
Ialse
true
b) arit
arit
Ialse
true
c) amit
amit
Ialse
true
d) arit
amit
true
true

Q12) Which one does not extend java.lang.Number
1)Integer
2)Boolean
3)Character
4)Long
5)Short

Q13) Which one does not have a valueOI(String) method
1)Integer
2)Boolean
3)Character
4)Long
5)Short

Q.14) What is the output oI Iollowing (Assuming written inside main)
String s1 "Amit";
String s2 "Amit";
String s3 new String("abcd");
String s4 new String("abcd");
System.out.println(s1.equals(s2));
System.out.println((s1s2));
System.out.println(s3.equals(s4));
System.out.println((s3s4));
a) true
true
true
Ialse
b) true
true
true
true
c) true
Ialse
true
Ialse

Q15. Which checkbox will be selected in the Iollowing code ( Assume with main and
added to a Frame)
Frame myFrame new Frame("Test");
CheckboxGroup cbg new CheckboxGroup();
Checkbox cb1 new Checkbox("First",true,cbg);
Checkbox cb2 new Checkbox("Scond",true,cbg);
Checkbox cb3 new Checkbox("THird",Ialse,cbg);
cbg.setSelectedCheckbox(cb3);
myFrame.add(cb1);
myFrame.add(cb2);
myFrame.add(cb3);
a) cb1
b) cb2,cb1
c) cb1,cb2,cb3
d) cb3

Q16) Which checkbox will be selected in the Iollowing code ( Assume with main and
added to a Frame)
Frame myFrame new Frame("Test");
CheckboxGroup cbg new CheckboxGroup();
Checkbox cb1 new Checkbox("First",true,cbg);
Checkbox cb2 new Checkbox("Scond",true,cbg);
Checkbox cb3 new Checkbox("THird",true,cbg);
myFrame.add(cb1);
myFrame.add(cb2);
myFrame.add(cb3);
a) cb1
b) cb2,cb1
c) cb1,cb2,cb3
d) cb3

Q17) What will be the output oI line 5
1 Choice c1 new Choice();
2 c1.add("First");
3 c1.addItem("Second");
4 c1.add("Third");
5 System.out.println(c1.getItemCount());
a) 1
b) 2
c) 3
d) None oI the above

Q18) What will be the order oI Iour items added
Choice c1 new Choice();
c1.add("First");
c1.addItem("Second");
c1.add("Third");
c1.insert("Lastadded",2);
System.out.println(c1.getItemCount());
a) First,Second,Third,Fourth
b) First,Second,Lastadded,Third
c) Lastadded,First,Second,Third

Q19) Answer based on Iollowing code
1 Choice c1 new Choice();
2 c1.add("First");
3 c1.addItem("Second");
4 c1.add("Third");
5 c1.insert("Lastadded",1000);
6 System.out.println(c1.getItemCount());
a) Compile time error
b) Run time error at line 5
c) No error and line 6 will print 1000
d) No error and line 6 will print 4

Q20) Which one oI the Iollowing does not extends java.awt.Component
a) CheckBox
b) Canvas
c) CheckbocGroup
d) Label

Q21) What is deIault layout manager Ior panels and applets?
a) Flowlayout
b) Gridlayout
c) BorderLayout

Q22) For awt components which oI the Iollowing statements are true?
a) II a component is not explicitly assigned a Iont, it usese the same Iont that it container
uses.
b) II a component is not explicitly assigned a Ioreground color , it usese the same
Ioreground color that it container uses.
c) II a component is not explicitly assigned a backround color , it usese the same
background color that it container uses.
d) II a component is not explicitly assigned a layout manager , it usese the same layout
manager that it container uses.

Q23)java.awt.Component class method getLocation() returns Point (containg x and y
cordinate).What does this x and y speciIy
a) SpeciIy the postion oI components lower-leIt component in the coordinate space oI the
component's parent.
b) SpeciIy the postion oI components upper-leIt component in the coordinate space oI the
component's parent.
c) SpeciIy the postion oI components upper-leIt component in the coordinate space oI the
screen.

Q24. Q. What will be the output oI Iollwing

double d1 -0.5d;
System.out.println("Ceil Ior d1 " Math.ceil(d1));
System.out.println("Floor Ior d1 " Math.Iloor(d1));
}
Answers:
a) Ceil Ior d1 0
Floor Ior d1 -1;
b) Ceil Ior d1 0
Floor Ior d1 -1.0;
c) Ceil Ior d1 0.0
Floor Ior d1 -1.0;
d) Ceil Ior d1 -0.0
Floor Ior d1 -1.0;

Q25. What is the output oI Iollowing

Iloat I4 -5.5I;
Iloat I5 5.5I;
Iloat I6 -5.49I;
Iloat I7 5.49I;
System.out.println("Round I4 is " Math.round(I4));
System.out.println("Round I5 is " Math.round(I5));
System.out.println("Round I6 is " Math.round(I6));
System.out.println("Round I7 is " Math.round(I7));
}
a)Round I4 is -6
Round I5 is 6
Round I6 is -5
Round I7 is 5
b)Round I4 is -5
Round I5 is 6
Round I6 is -5
Round I7 is 5

Q26. Given Integer.MINVALUE -2147483648
Integer.MAXVALUE 2147483647
What is the output oI Iollowing

Iloat I4 Integer.MINVALUE;
Iloat I5 Integer.MAXVALUE;
Iloat I7 -2147483655I;
System.out.println("Round I4 is " Math.round(I4));
System.out.println("Round I5 is " Math.round(I5));
System.out.println("Round I7 is " Math.round(I7));
}
a)Round I4 is -2147483648
Round I5 is 2147483647
Round I7 is -2147483648
b)Round I4 is -2147483648
Round I5 is 2147483647
Round I7 is -2147483655

Q27)
1 Boolean b1 new Boolean("TRUE");
2 Boolean b2 new Boolean("true");
3 Boolean b3 new Boolean("JUNK");
4 System.out.println("" b1 b2 b3);
a) Comiler error
b) RunTime error
c)truetrueIalse
d)truetruetrue

Q 28) In the above question iI line 4 is changed to
System.out.println(b1b2b3); The output is
a) Compile time error
b) Run time error
c) truetrueIalse
d) truetruetrue

Q 29. What is the output

Float I1 new Float("4.4e99I");
Float I2 new Float("-4.4e99I");
Double d1 new Double("4.4e99");
System.out.println(I1);
System.out.println(I2);
System.out.println(d1);
}
a) Runtime error
b) InIinity
-InIinity
4.4E99
c) InIinity
-InIinity
InIinity
d) 4.4E99
-4.4E99
4.4E99

Q30 Q. Which oI the Iollowing wrapper classes can not
take a "String" in constructor
1) Boolean
2) Integer
3) Long
4) Character
5) Byte
6) Short

Q31. What is the output oI Iollowing
Double d2 new Double("-5.5");
Double d3 new Double("-5.5");
System.out.println(d2d3);
System.out.println(d2.equals(d3));
a) true
true
b) Ialse
Ialse
c) true
Ialse
d) Ialse
true

Q32) Which one oI the Iollowing always honors the components's preIerred size.
a) FlowLayout
b) GridLayout
c) BorderLayout

Q33) Look at the Iollowing code
import java.awt.*;
public class visual extends java.applet.Applet
static Button b new Button("TEST");
public void init()
add(b);
}
public static void main(String args||)
Frame I new Frame("Visual");
I.setSize(300,300);
I.add(b);
I.setVisible(true);
}
}
What will happen iI above code is run as a standalone application
a) Displays an empty Irame
b) Displays a Irame with a button covering the entire Irame
c) Displays a Irame with a button large enough to accomodate its label.

Q34 II the code in Q33 is compiled and run via appletviewer what will happen
a) Displays an empty applet
b) Displays a applet with a button covering the entire Irame
c) Displays a applet with a button large enough to accomodate its label.

Q35. What is the output
public static void main(String args||)
Frame I new Frame("Visual");
I.setSize(300,300);
I.setVisible(true);
Point p I.getLocation();
System.out.println("x is " p.x);
System.out.println("y is " p.y);
}
a) x is 300
y is 300
b) x is 0
y is 0
c) x is 0
y is 300

Q36) Which one oI the Iollowing always ignores the components's preIerred size.
a) FlowLayout
b) GridLayout
c) BorderLayout

Q37) Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
\dir1\IO.class -- IO.class is under dir1
Consider the Iollowing code
import java.io.*;
public class IO
public static void main(String args||)
File I new File("..\\12345.msg");
try
System.out.println(I.getCanonicalPath());
System.out.println(I.getAbsolutePath());
}catch(IOException e)
System.out.println(e);
}
}
}
What will be the output oI running "java IO" Irom C:\java\dir1
a) C:\java\12345.msg
C:\java\dir1\..\12345.msg
b) C:\java\dir1\12345.msg
C:\java\dir1\..\12345.msg
c) C:\java\dir1\..\12345.msg
C:\java\dir1\..\12345.msg


Q 38) Suppose we copy IO.class Irom C:\java\dir1 to c:\java
What will be the output oI running "java IO" Irom C:\java.
a) C:\java\12345.msg
C:\java\..\12345.msg
b) C:\12345.msg
C:\java\..\12345.msg
c) C:\java\..\12345.msg
C:\java\\..\12345.msg

Q39) Which one oI the Iollowing methods oI java.io.File throws IOException and why
a) getCanonicalPath and getAbsolutePath both require Iilesystem queries.
b) Only getCannonicalPath as it require Iilesystem queries.
c) Only getAbsolutePath as it require Iilesystem queries.

Q40) What will be the output iI
Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
\dir1\IO.class -- IO.class is under dir1
import java.io.*;
public class IO
public static void main(String args||)
File I new File("12345.msg");
String arr|| I.list();
System.out.println(arr.length);
}
}
a) Compiler error as 12345.msg is a Iile not a directory
b) java.lang.NullPointerException at run time
c) No error , but nothing will be printed on screen

Q41) What will be the output
Consider a directory structure like this (NT or 95)
C:\JAVA\12345.msg --FILE
import java.io.*;
public class IO
public static void main(String args||)
File I1 new File("\\12345.msg");
System.out.println(I1.getPath());
System.out.println(I1.getParent());
System.out.println(I1.isAbsolute());
System.out.println(I1.getName());
System.out.println(I1.exists());
System.out.println(I1.isFile());
}
}
a) \12345.msg
\
true
12345.msg
true
true
b) \12345.msg
\
true
\12345.msg
Ialse
Ialse
c) 12345.msg
\
true
12345.msg
Ialse
Ialse
d) \12345.msg
\
true
12345.msg
Ialse
Ialse

Q42) II in question no 41 the line
File I1 new File("\\12345.msg"); is replaced with File I1 new File("12345.msg");
What will be the output
a) 12345.msg
\
true
12345.msg
true
true
b) 12345.msg
null
true
12345.msg
true
true

c) 12345.msg
null
Ialse
12345.msg
true
true
d) \12345.msg
\
true
12345.msg
Ialse
Ialse





ANSWERS :-

1) a)
2) b)
3) c)
4) b)
5) C)
6) a)As you can not override a method with weaker access privileges
7) c)As you can access a protected variable in the same package.
8) a) Because protected variables and methods can not be accssed in another package
directly. They can only be accessed iI the class is subclassed and instance oI subclass is
used.
9) a)
10) d)As String is imutable.so s1 is always "amit". and s2 is "aiit".
11) a) s3s4 is true because java points both s3 and s4 to same memory location in
string pool
12) 2) and 3)
13) 3)
14) a)
15) d) As in a CheckboxGroup only one can be selected
16) d) As in a CheckboxGroup only one can be selected
17) c)
18) b)
19) d)
20) c)
21) a)
22) a),b),c)
23) b)
24) d) as 0.0 is treated diIIerently Irom -0.0
25) b)
26) a) //Reason II the argument is negative inIinity or any value less than or equal to the
value oI Integer.MINVALUE, the result is equal to the value oI Integer.MINVALUE.
II the argument is positive inIinity or any value greater than or equal to the value oI
Integer.MAXVALUE, the result is equal to the value oI Integer.MAXVALUE. // From
JDK api documentation
27) c)
28) a) As there is no method to support Boolean Boolean Boolean b1 new
Boolean("TRUE"); Think -----~System.out.println(b1); // Is this valid or not?
29) b)
30) 4)
31) d)
32) a)
33) b) Reason- Frame uses Border Layout which places the button to CENTRE (By
deIault) and ignores Button's preIerred size.
34) c) Reason- Applet uses FlowLayout which honors Button's preIerred size.
35) b) Because postion is always relative to parent container and in this. case Frame I is
the topemost container
36) b)
37) a) as getCanonicalPath Returns the canonical Iorm oI this File object's pathname. The
precise deIinition oI canonical Iorm is system-dependent, but it usually speciIies an
absolute pathname in which all relative reIerences and reIerences to the current user
directory have been completely resolved. WHERE AS getAbsolutePath Returns the
absolute pathname oI the Iile represented by this object. II this object represents an
absolute pathname, then return the pathname. Otherwise, return a pathname that is a
concatenation oI the current user directory, the separator character, and the pathname oI
this Iile object.
38) b)
39) b)
40) b)
41) d)
42) c)


Cracked By Charitra Choudhary, INDIA
Any Help, Plz Feel Free to mail (Charitra.choudharyrediIImail.com)
MCSE, MCSE, CCNA, Comptia A, N, JCP, MCAD, MCSD, MVP


Question 1
What will happen iI you compile/run this code?

1: public class Q1 extends Thread
2:
3: public void run()
4:
5: System.out.println("BeIore start method");
6: this.stop();
7: System.out.println("AIter stop method");
8: }
9:
10: public static void main(String|| args)
11:
12: Q1 a new Q1();
13: a.start();
14: }
15: }

A) Compilation error at line 7.
B) Runtime exception at line 7.
C) Prints "BeIore start method" and "AIter stop method".
D) Prints "BeIore start method" only.


Question 2
What will happen iI you compile/run the Iollowing code?

1: class Test
2:
3: static void show()
4:
5: System.out.println("Show method in Test class");
6: }
7:}
8:
9: public class Q2 extends Test
10:
11: static void show()
12:
13: System.out.println("Show method in Q2 class");
14: }
15: public static void main(String|| args)
16:
17: Test t new Test();
18: t.show();
19: Q2 q new Q2();
20: q.show();
21:
22: t q;
23: t.show();
24:
25: q t;
26: q.show();
27: }
28: }

A) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Q2 class"
"Show method in Q2 class"

B) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Test class"

C) prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Q2 class"

D) Compilation error.




Question 3
The Iollowing code will give
1: class Test
2:
3: void show()
4:
5: System.out.println("non-static method in Test");
6: }
7: }
8: public class Q3 extends Test
9:
10: static void show()
11:
12: System.out.println("Overridden non-static method in Q3");
13: }
14:
15: public static void main(String|| args)
16:
17: Q3 a new Q3();
18: }
19: }

A) Compilation error at line 3.
B) Compilation error at line 10.
C) No compilation error, but runtime exception at line 3.
D) No compilation error, but runtime exception at line 10.


Question No :4
The Iollowing code will give

1: class Test
2:
3: static void show()
4:
5: System.out.println("Static method in Test");
6: }
7: }
8: public class Q4 extends Test
9:
10: void show()
11:
12: System.out.println("Overridden static method in Q4");
13: }
14: public static void main(String|| args)
15:
16: }
17: }

A) Compilation error at line 3.
B) Compilation error at line 10.
C) No compilation error, but runtime exception at line 3.
D) No compilation error, but runtime exception at line 10.



Question No :5
The Iollowing code will print

1: int i 1;
2: i 31;
3: i ~~ 31;
4: i ~~ 1;
5:
6: int j 1;
7: j 31;
8: j ~~ 31;
9:
10: System.out.println("i " i );
11: System.out.println("j " j);

A) i 1
j 1

B) i -1
j 1

C) i 1
j -1

D) i -1
j -1



Question No :6
The Iollowing code will print

1: Double a new Double(Double.NaN);
2: Double b new Double(Double.NaN);
3:
4: iI( Double.NaN Double.NaN )
5: System.out.println("True");
6: else
7: System.out.println("False");
8:
9: iI( a.equals(b) )
10: System.out.println("True");
11: else
12: System.out.println("False");

A) True
True

B) True
False

C) False
True

D) False
False



Question No :7
1: iI( new Boolean("true") new Boolean("true"))
2: System.out.println("True");
3: else
4: System.out.println("False");

A) Compilation error.
B) No compilation error, but runtime exception.
C) Prints "True".
D) Prints "False".



Question No :8


1: public class Q8
2:
3: int i 20;
4: static
5:
6: int i 10;
7:
8: }
9: public static void main(String|| args)
10:
11: Q8 a new Q8();
12: System.out.println(a.i);
13: }
14: }

A) Compilation error, variable "i" declared twice.
B) Compilation error, static initializers Ior initialization purpose only.
C) Prints 10.
D) Prints 20.



Question No :9

The Iollowing code will give

1: Byte b1 new Byte("127");
2:
3: iI(b1.toString() b1.toString())
4: System.out.println("True");
5: else
6: System.out.println("False");

A) Compilation error, toString() is not avialable Ior Byte.
B) Prints "True".
C) Prints "False".



Question No :10
What will happen iI you compile/run this code?

1: public class Q10
2:
3: public static void main(String|| args)
4:
5: int i 10;
6: int j 10;
7: boolean b Ialse;
8:
9: iI( b i j)
10: System.out.println("True");
11: else
12: System.out.println("False");
13: }
14: }

A) Compilation error at line 9 .
B) Runtime error exception at line 9.
C) Prints "True".
D) Prints "Fasle".

Question 11
What will happen iI you compile/run the Iollowing code?

1: public class Q11
2:
3: static String str1 "main method with String|| args";
4: static String str2 "main method with int|| args";
5:
6: public static void main(String|| args)
7:
8: System.out.println(str1);
9: }
10:
11: public static void main(int|| args)
12:
13: System.out.println(str2);
14: }
15: }

A) Duplicate method main(), compilation error at line 6.
B) Duplicate method main(), compilation error at line 11.
C) Prints "main method with main String|| args".
D) Prints "main method with main int|| args".



Question 12
What is the output oI the Iollowing code?

1: class Test
2:
3: Test(int i)
4:
5: System.out.println("Test(" i ")");
6: }
7: }
8:
9: public class Q12
10:
11: static Test t1 new Test(1);
12:
13: Test t2 new Test(2);
14:
15: static Test t3 new Test(3);
16:
17: public static void main(String|| args)
18:
19: Q12 Q new Q12();
20: }
21: }

A) Test(1)
Test(2)
Test(3)

B) Test(3)
Test(2)
Test(1)

C) Test(2)
Test(1)
Test(3)

D) Test(1)
Test(3)
Test(2)



Question 13
What is the output oI the Iollowing code?

1: int i 16;
2: int j 17;
3:
4: System.out.println("i ~~ 1 " (i ~~ 1));
5: System.out.println("j ~~ 1 " (j ~~ 1));

A) Prints "i ~~ 1 8"
"j ~~ 1 8"

B) Prints "i ~~ 1 7"
"j ~~ 1 7"

C) Prints "i ~~ 1 8"
"j ~~ 1 9"

D) Prints "i ~~ 1 7"
"j ~~ 1 8"



Question 14
What is the output oI the Iollowing code?

1: int i 45678;
2: int j ~i;
3:
4: System.out.println(j);

A) Compilation error at line 2. ~ operator applicable to boolean values only.
B) Prints 45677.
C) Prints -45677.
D) Prints -45679.



Question 15
What will happen when you invoke the Iollowing method?

1: void inIiniteLoop()
2:
3: byte b 1;
4:
5: while ( b ~ 0 )
6: ;
7: System.out.println("Welcome to Java");
8: }

A) The loop never ends(inIiniteLoop).
B) Prints "Welcome to Java".
C) Compilation error at line 5. operator should not be used Ior byte type variables.
D) Prints nothing.



Question 16
In the Iollowing applet, how many Buttons will be displayed?

1: import java.applet.*;
2: import java.awt.*;
3:
4: public class Q16 extends Applet
5:
6: Button okButton new Button("Ok");
7:
8: public void init()
9:
10: add(okButton);
11: add(okButton);
12: add(okButton);
13: add(okButton);
14:
15: add(new Button("Cancel"));
16: add(new Button("Cancel"));
17: add(new Button("Cancel"));
18: add(new Button("Cancel"));
19:
20: setSize(300,300);
21: }
22: }

A) 1 Button with label "Ok" and 1 Button with label "Cancel" .
B) 1 Button with label "Ok" and 4 Buttons with label "Cancel" .
C) 4 Buttons with label "Ok" and 1 Button with label "Cancel" .
D) 4 Buttons with label "Ok" and 4 Buttons with label "Cancel" .



Question 17
In the Iollowing, which is correct Container-DeIault layout combination?

A) Applet - FlowLayout
B) Applet - BorderLayout
C) Applet - CardLayout
D) Frame - Flowlayout
E) Frame - BorderLayout
F) Frame - CardLayout
G) Panel - FlowLayout
H) Panel - BorderLayout.



Question 18
What is the output oI the Iollowing code?

1: String str "Welcome";
2:
3: str.concat(" to Java!");
4:
5: System.out.println(str);

A) Strings are immutable, compilation error at line 3.
B) Strings are immutable, runtime exception at line 3.
C) Prints "Welcome".
D) Prints "Welcome to Java!".



Question 19
What is the output oI the Iollowing code?

1: class MyClass
2:
3: static int maxElements;
4:
5: MyClass(int maxElements)
6:
7: this.maxElements maxElements;
8: }
9:
10: }
11:
12: public class Q19
13:
14: public static void main(String|| args)
15:
16:
17: MyClass a new MyClass(100);
18: MyClass b new MyClass(100);
19:
20: iI(a.equals(b))
21: System.out.println("Objects have the same values");
22: else
23: System.out.println("Objects have diIIerent values");
24: }
25: }

A) Compilation error at line 20. equals() method was not deIined.
B) Compiles Iine, runtime exception at line 20.
C) Prints "Objects have the same values".
D) Prints "Objects have diIIerent values";



Question 20
1: import java.applet.*;
2: import java.awt.*;
3:
4: public class Q20 extends Applet
5:
6: Button okButton new Button("Ok");
7:
8: public void init()
9:
10: setLayout(new BorderLayout());
11:
12: add("South", okButton);
13: add("North", okButton);
14: add("East", okButton);
15: add("West", okButton);
16: add("Center", okButon);
17:
18: setSize(300,300);
19: }
20: }

The above Applet will display

A) Five Buttons with label "Ok" at Top, Bottom, Right, LeIt and Center oI the Applet.
B) Only one Button with label "Ok" at the Top oI the Applet.
C) Only one Button with label "Ok" at the Bottom oI the applet.
D) Only one Button with label "Ok" at the Center oI the Applet.


Question 21
What will happen iI you compile/run the Iollowing code?

1: public class Q21
2:
3: int maxElements;
4:
5: void Q21()
6:
7: maxElements 100;
8: System.out.println(maxElements);
9: }
10:
11: Q21(int i)
12:
13: maxElements i;
14: System.out.println(maxElements);
15: }
16:
17: public static void main(String|| args)
18:
19: Q21 a new Q21();
20: Q21 b new Q21(999);
21: }
22: }

A) Prints 100 and 999.
B) Prints 999 and 100.
C) Compilation error at line 3, variable maxElements was not initialized.
D) Compillation error at line 19.


Question 22
What will happen iI run the Iollowing code?

1: Boolean|| b1 new Boolean|10|;
2:
3: boolean|| b2 new boolean|10|;
4:
6: System.out.println("The value oI b1|1| " b1|1|);
7: System.out.println("The value oI b2|1| " b2|1|);

A) Prints "The value oI b1|1| Ialse"
"The value oI b2|1| Ialse".

B) Prints "The value oI b1|1| null"
"The value oI b2|1| null".

C) Prints "The value oI b1|1| null"
"The value oI b2|1| Ialse".

D) Prints "The value oI b1|1| Ialse"
"The value oI b2|1| null".



Question 23
Which oI the Iollowing are valid array declarations/deIinitions?
1: int iArray1|10|;
2: int iArray2||;
3: int iArray3|| new int|10|;
4: int iArray4|10| new int|10|;
5: int ||iArray5 new int|10|;
6: int iArray6|| new int||;
7: int iArray7|| null;
A) 1.
B) 2.
C) 3.
D) 4.
E) 5.
F) 6.
G) 7.


Question 24
What is the output Ior the Iollowing lines oI code?
1: System.out.println(" " 2 3);
2: System.out.println(2 3);
3: System.out.println(2 3 "");
4: System.out.println(2 "" 3);

A) Compilation error at line 3
B) Prints 23, 5, 5 and 23.
C) Prints 5, 5, 5 and 23.
D) Prints 23, 5, 23 and 23.



Question 25
The Iollowing declaration(as a member variable) is legal.
static Iinal transient int maxElements 100;
A) True.
B) False.



Question 26
What will happen iI you compile/run the Iollowing lines oI code?
1: int|| iArray new int|10|;
2:
3: iArray.length 15;
4:
5: System.out.println(iArray.length);
A) Prints 10.
B) Prints 15.
C) Compilation error, you can't change the length oI an array.
D) Runtime exception at line 3.


Question 27
What will happen iI you compile/run the Iolowing lines oI code?
1: Vector a new Vector();
2:
3: a.addElement(10);
4:
5: System.out.println(a.elementAt(0));

A) Prints 10.
B) Prints 11.
C) Compilation error at line 3.
D) Prints some garbage.

Question 28
What will happen iI you invoke the Iollowing method?
1: public void check()
2:
3: System.out.println(Math.min(-0.0,0.0));
4: System.out.println(Math.max(-0.0,0.0));
5: System.out.println(Math.min(-0.0,0.0) Math.max(0.0,0.0));
6: }

A) prints -0.0, 0.0 and Ialse.
B) prints -0.0, 0.0 and true.
C) prints 0.0, 0.0 and Ialse.
D) prints 0.0, 0.0 and true.


Question 29
What will happen iI you compile/run this code?
1: int i 012;
2: int j 034;
3: int k 056;
4: int l 078;
5:
6: System.out.println(i);
7: System.out.println(j);
8: System.out.println(k);
A) Prints 12,34 and 56.
B) Prints 24,68 and 112.
C) Prints 10, 28 and 46.
D) Compilation error.

Question 30
When executed the Iollowing line oI code will print
System.out.println(-1 * Double.NEGATIVEINFINITY);

A) -InIinity
B) InIinity
C) NaN
D) -NaN








ANSWERS
Question No: 1
D. AIter the execution oI stop() method, thread won't execute any more statements.

Question No: 2
D. Explicit casting is required at line 25.

Question No: 3
B. You cann't override an non-static method with static method.

Question No: 4
B. You cann't override a static method with non-static method.

Question No: 5
D.

Question No: 6
C.

Question No: 7
D.

Question No: 8
D. Here the variable '"i" deIined in static initializer is local to that block only.
The statements in the static initializers will be executed (only once) when the class is
Iirst created.

Question No: 9
C.

Question No: 10
C. Conditional operators have high precedence than assignment operators.

Question No 11
C. Here the main method was overloaded, so it won't give compilation error.

Question No 12
D. No matter where they declared, static variables will be intitialized beIore non-static
variables.

Question No 13
A. 16 ~~ 1 is 8 and 17 ~~ 1 also 8.

Question No 14
D. Java allows you to use ~ operator Ior integer type variables. The simple way to
calculate is ~i (- i) - 1.

Question No 15
B. Here the variable 'b' will go upto 127.
AIter that overIlow will occur, so 'b' will be set to -ve value, the loop ends and prints
"Welcome to Java"

Question No 16
B.

Question No 17
A, E and G. For Applets and Panels FlowLayout is the deIault one, BorderLayout is
deIault Ior Window and Frames.

Question No 18
C. Strings are immutable. So str.concat("to Java!") will not append anything to str.
InIact it will create another string "Welcome to Java!" and leaves it.

Question No 19
D. equals() method was available in base class Object. So it won't give any
compilation error.
Here MyClass is a user-deIined class, so the user has to implement equals() method
according to his requirments.

Question No 20
D.

Question No 21
D. Constructors should not return any value. Java won't allow to indicate with void.
In this case void Q21() is an ordinary method which has the same name oI the Class.

Question No 22
C. By deIault objects will be initialized to null and primitives to their corresponding
deIault vaulues.
The same rule applies to array oI objects and primitves.

Question No 23
B,C,E and G. You can't speciIy the array dimension in type speciIication(leIt hand
side),
so A and D are invalid. In line 6 the array dimension is missing(right hand side) so F
is invalid.
You can intialize an array with null. so G is valid.

Question No 24
B.

Question No 25
A.

Question No 26
C. Once array is created then it is not possible to change the length oI the array.

Question No 27
C. You can't add primitives to Vector. Here 10 is int type primitive.

Question No 28
B. The order oI Iloating/double values is
-InIinity --~ Negative Numbers/Fractions --~ -0.0 --~ 0.0 --~ Positive
Numbers/Fractions --~ InIinity.

Question No 29
D. Here integers are assinged by octal values. Octal numbers will contain digits Irom 0
to 7.
8 is illegal digit Ior an octal value, so you get compilation error.

Question No 30
B. Compile and see the result.


Cracked By Charitra Choudhary, INDIA
Any Help, Plz Feel Free to mail (Charitra.choudharyrediIImail.com)
MCSE, MCSE, CCNA, Comptia A, N, JCP, MCAD, MCSD, MVP


QUESTIONS :-

1.Which statement about the garbage collection mechanism are true?
A.Garbage collection require additional programe code in cases where
multiple threads are running.
B.The programmer can indicate that a reIerance through a local
variable is no longer oI interest.
C.The programmer has a mechanism that explicity and immediately Irees
the memory used by Java objects.
D.The garbage collection mechanism can Iree the memory used by Java
Object at explection time.
E.The garbage collection system never reclaims memory Irom objects
while are still accessible to running user thread.


2.Give the Iollowing method:
1) public void method()
2) String a,b;
3) anew String("hello world");
4) bnew String("game over");
5) System.out.println(ab"ok");
6) anull;
7) ab;
8) System.out.println(a);
9) }
In the absence oI compiler optimization,which line is the earliest point the
object a reIered is deIinitely elibile to be garbage collected?
A.3 B.5 C.6 D.7 E.9


3.In the class java.awt.AWTEvent,which is the parent class upon which jdk1.1
awt events are based there is a method called getID(),
which phrase most accerrately describes in signiIicance oI the reture value
oI this method?
A.It is a reIerence to the object directly aIIected by the cause oI
the event.
B.It is an indication oI the nature oI the cause oI the event.
C.It is an indication oI the position oI the mouse when it caused the
event.
D.In the case oI a mouse click,it is an indication oI the text under
the mouse at the time oI the event.
E.It tells the state oI certain keys on the keybord at the time oI
the event.
F.It is an indication oI the time at which the event occurred.




4. Which statement about listener is true?
A.Most component allow multiple listeners to be added.
B.II mutiple listener be add to a single component,the event only
aIIected one listener.
C.Component don't allow multiple listeners to be add.
D.The listener mechanism allows you to call an addListener method as
many times as is needed,speciIying as many diIIerent listeners as your design
requires.




5.Give the Iollowing code: public class Example
public static void main(String args||)
int I0;
do
System.out.println("Doing it Ior I is:" I );
}while(--i);
System.out.println("Finish"); }
}
Which will be output:
A.Doing it Ior I is 3 B.Doing it Ior I is 1 C.Doing it
Ior I is 2
D.Doing it Ior I is 0 E.Doing iI Ior I is -1 F.Finish




6.Give the code Iragment:
1) switch(x)
2) case 1: System.out.println("Test 1"); break;
3) case 2:
4) case 3:System.out.println("Test 2"); break;
5) deIault: System.out.println("end");
6) }which value oI x would cause "Test 2" to the output:
A.1 B.2 C.3 D.deIault



7.Give incompleted method: 1)
2) iI(unsaIe()) //do something...}
3) else iI(saIe())//do the other...} 4} }
The method unsaIe() will throw an IOException,which completes the method oI
declaration when added at line one?
A.public IOException methodName() B.public void methodName()
C.public void methodName() throw IOException
D.public void methodName() throws IOException
F.public void methodName() throws Exception8.Give the code Iragment:




8. iI(x~4) System.out.println("Test 1");}
else iI(x~9)
System.out.println("Test 2");} else
System.out.println("Test 3");}
Which range oI value oI x would produce oI output "Test 2"?
A.x4 B.x~4 C.x~9 D.None



9.Give the Iollowing method:
public void example()
try
unsaIe();
System.out.println("Test 1");
}catch(SaIeException e)System.out.println("Test 2");
}IinallySystem.out.println("Test 3");}
System.out.println("Test 4"); }
Which will display iI method unsaIe() run normally?
A.Test 1 B.Test 2 C.Test 3
D.Test 4



10.Which method you deIine as the starting point oI new thread in a class
Irom which new the thread can be excution?
A.public void start() B.public void run()
C.public void int()
D.public static void main(String args||) E.public void
runnable()




11.What wight cause the current thread to stop excutings?
A.thread oI higher priority become ready.
B.method sleep() be called.
C.method stop() be called D.method suspend() be called.
E.method wait() be called
12.Which modiIier should be applied to a method Ior the lock oI object this
to be obtained prior to excution any oI the mehod body?
A.synchronized B.abstract C.Iinal D.static
E.public




13.The Iollowing code is entire contents oI a Iile called
Example.java,causes precisely one error during compilation:
1) class SubClass extends BaseClass 2) }
3) class BaseClass 4) String str;
5) public BaseClass()
6) System.out.println("ok");}
7) public BaseClass(String s)
8) strs;
9) public class Example
10) public void method()
11) SubClass snew
SubClass("hello");
12) BaseClass bnew
BaseClass("world");
13) } 14) }
15) } 16) }
Which line would be cause the error? A.9 B.10 C.11
D.12



14.Which statement is correctly declare a variable a which is suitable Ior
reIering to an array oI 30 string empty object?
A.String ||a B.String a|| D.char a||||
E.String a|50| F.Object a|50|



15.Give the Iollowing java sourse Iragement: //point x
public class Interesting //do something }
which statement is correctly Java syntax ant point x?
A.import java.awt.*; B.package mypackage
C.static int PI3.14
D.public class MyClass//do other thing...} E.class
MyClass//do something...}



16.Give this class outline: class Example private int
x;
//rest oI class body... }
Assuming that x invoked by the code java Example,which statement can made
this.x be accessible in main() method oI Example.java:
A.Change private int x to public int x B.change private int x to
static int x
C.Change private int x to protected int x D.change private int x to
Iinal int x





17.The piece oI preliminary analsis work describes a class that will be used
Irequently in many unrelated parts oI a project:
"The polygon object is a drawable,A polygon has vertex inIormation
stored in a vector,a color,
length and width."Which Data type would be used?
A.Vector B.int C.String
D.Color E.Date




18.A class design requires that a member variable should be accessible only
by same package,which modiIer word should be used:
A.protected B.public C.no modiIer
D.private

19.Which declares Ior a native method in a java class corrected?
A.public native void method() }
B.public native void method();
C.public native method(); D.public void
method()native;}
E.public void native method();


20.Which modiIer should be applied to a declaration oI a class member
variable Ior the value oI variable to remain constant aIter the creation oI
the object?(short answer)



21.Which is the main() method's return oI a application?
A.String B.byte C.char D.void



22.Which is corrected argument oI main() method oI a applicaton?
A.String args B.String ar|| C.Char args||||
D.StringBuIIer arg||




23."The Employee object is a person,An Employee has appointment store in a
vector,a hire date and a number oI dependents."
short anwser:use shortest statement deIine a class oI Employee.



24.Give the Iollowing class deIination inseparate source Iiles:
public class Example public Example()//do something}
protected Example()// do something}
protected void method()//do something} }
public class Hello extends Example// member method and member
variable}
Which methods are corrected added to the class Hello?
A.public void Example()} B.public void method()}
C.protected void method()} D.private void method()
E.private otherMethod()}



25. Float snew Float(0.9F); Float tnew Float(0.9F);
Double unew Double(0.9);Which expression's result is true?
A.st; B.s.equal(t); C.su D.t.equal(u)








26.Give Iollowing class: class AClass private long
val;
public AClass(long v)valv;}
public static void main(String args||)
AClass xnew AClass(10L);
AClass ynew AClass(10L);
AClass zy;
long a10L;
int b10; } }
Which expression's result is true?
A.a b; B.a x; C.y z; D.x
y;
E.a 10.0;



27.A socket object has been created and connected to a standard internet
sevice on a remote network server.Which construction give the most suitable
means Ior reading ASCII data one line at a time Irom the socket?
A.InputStream ins.getInputStream();
B.DataInputStream innew DataInputstream(s.getInputStream());
C.ByteArrayInputStream innew
ByteArrayInputStream(s.getInputStream());
D.BuIIeredReader innew BuIIeredReader(new
InputStreamReader(s.getInputStream()));
E.BuIIeredReader innew BuIIeredReader(new
InputStreamReader(s.getInputStream()),"8859-1");




28.String s"Example String"; Which operation is legal?
A.s~~~3; B.int s.length(); C.s|3|"x";
D.String short ss.trim(); E.String
t"root"s;



29.Give: String str"goodby"; Which operation is legal?
A.char cs|3|; B.int is.length(); C.s~~2;
D.String lower ss.toLowerCase(); E.s"long

ago";





30.What use to position a Button in a Frame,width oI Button is aIIected by
the Frame size,which Layout Button will be set to?
A.FlowLayout; B.GridLayout; C.North oI
BorderLayout
D.South oI BorderLayout D.Ease or West oI
BorderLayout



31.What use to position a Button in a Frame,size oI Button is not aIIected
by the Frame size,which Layout Button will be set to?
A.FlowLayout; B.GridLayout; C.North oI
BorderLayout
D.South oI BorderLayout D.Ease or West oI
BorderLayout




32.An AWT GUI under exposure condition,which one or more method will be invok
when it redraw?
A.paint(); B.update(); C.repaint(); D.drawing();




33.Select valid identiIier oI Java:
A.userName B.passwd C.3dgame D.$charge
E.this




34.Which are Java keyword?
A.goto B.null C.FALSE D.native
E.const




35.Run a corrected class:java -cs AClass a b c
Which statement is true?
A.args|0|"-cs"; B.args|1|"a b c";
C.args|0|"java";
D.args|0|"a"; E.args|1|'b';36.Give the Iollowing java
class:
public class Example static int x||new int|15|;
public static void main(String args||)
System.out.println(x|5|); } }
Which statement is corrected?
A.When compile,some error will occur.
B.When run,some error will occur. C.Output is zearo.
D.Output is null.37.Give the Iollowing java class:
public class Example
public static void main(String args||)
static int x||new int|15|;
System.out.println(x|5|); } }
Which statement is corrected? A.When compile,some error will occur.
B.When run,some error will occur. C.Output is zearo.
D.Output is null.38. Short answer:
The decimal value oI i is 12,the octal i value is:39.short answer:
The decimal value oI i is 7,the hexadecimal is:




40.Which is the range oI char?
A.2-7~27-1 B.0~216-1 C.0~216 D.0~28



41.Which is the range oI int type?
A.2-16~2 16-1 B.2-31~ 2 31-1 C.2-32~2 32-1
D.2-64~2 64-1




42.Give the Iollowing class: public class Example
String strnew String("good");
char ch||'a','b','c'};
public static void main(String args||)
Example exnew Example();
ex.change(ex.str,ex.ch);
System.out.println(ex.str" and "ex.ch);
} public void change(String str,char ch||)
str"test ok";ch|0|"g"; }
} Which is the output:
A.good and abc B.good and gbc C.test ok and abc
D.test ok and gbc




43.Which code Iragments would correctly identiIy the number oI arguments
passed via
command line to a Javaapplication, excluding the name oI the class that is
being invoked?
A.int count args.length; B.int count args.length - l;
C.int count0; while (args |count| !null)
count ; D.int count0; while
(!(args|count|.equals(""))) count ;



44.FilterOutputStream is the parent class Ior BuIIeredOutputStream,
DataOutputStream and
PrintStream. Which classes are a valid argument Ior the constructor oI a
FilterOutputStream?
A.InputStream B.OutputStream C.File
D.RandomAccessFile E.StreamTokenizer




45.Given a TextArea using a proportional pitch Iont and constructed like
this:
TextArea t new TextArea("12345", 5, 5);
Which statement is true?
A.the displayed width shows exactly Iive characters one ach line
unless otherwise constrained
B.The displayed height is Iive lines unless otherwise
constrained.
C.The maximum number oI characters in a line will be Iive.
D.The user will be able to edit the character string
E.The displayed string can use multiple Ionts



46.Given a TextArea using a proportional pitch Iont and constructed like
this:
List lnew List(5,true); Which statement is true?
A.the displayed item exactly Iive line unless otherwise
constrained
B.The displayed item is Iive lines init.but can displayed more
than Iive Item by
C.The maximum number oI item in a list will be Iive.
D.The list is multiple mode
47.Given this skeleton oI a class currently under construction:
public class Example int x, y,z;
public Example(int a,int b)
//lots oI complex computation
xa;yb; }
public Example(int a, int b,int c)
// do everything the same as single argument
// version oI constructor
//including assignment x a,yb
zc; } }

What is the most concise way to code the "do everything..."part oI
the constructor taking two arguments? (short answer)





48.Which correctly create a two dimensional array oI integers?
A.int a|||| new int|10,10|
B.int a|10||10| new int||||;
C.int a|||| new int |10||10|;
D.int ||a|| new int |10||10|;
E.int ||a|| new int|10||10|;





49.Which are correct class declarations? Assume in each case that the text
constitutes the entire contents oI a Iile called Fred.java on a system with a
case-signiIicant Iile system.
A.public class Fred
public int x 0;
public Fred (int x)
this.x x;
} }
B.public class Ired
public int x 0;
public Ired (int x)
this.x x;
} }
C.public class Fred extends MyBaseClass,
MyOtherBaseClass
public int x 0;
public Fred (int xval)
x xval;
} }
D.protected class Fred
private int x 0;
private Fred (int xval)
x xval;
} }
E.import java.awt.*;
public class Fred extends Object
int x;
private Fred (int xval)
x xval;
} }
50.A class design requires that a particular member variable must be
accessible Ior direct access by any subclasses oI this class, but otherwise
not by classes which are not members oI the same package. What should be
done to achieve this?
A.The variable should be marked public
B.The variable should be marked private
C.The variable should be marked protected
D.The variable should have no special access modiIier
E.The variable should be marked private and an accessor method
provided

51.Which correctly create an array oI Iive empty Strings?
A.String a || new String |5|;
Ior (int i 0; i 5; a|i| "");
B.String a || "", "", "", "", ""};
C.String a |5|;
D.String |5| a;
E.String || a new String |5|;
Ior (int i 0; i 5; a|i| null);
52.Which cannot be added to a Container?
A.an Applet B.a Component
C.a Container D.a MenuComponent E.a panel
53.Which is the return value oI Event listener's method?
A.String B.AWTEvent C.void D.int
54.II we implements MouseEventListener,which is corrected argument oI it's
method?(short answer)
55.Use the oprator "~~" and "~~~".Which statement is true?
A.1010 0000 0000 0000 0000 0000 0000 0000~~4 give
0000 1010 0000 0000 0000 0000 0000 0000
B.1010 0000 0000 0000 0000 0000 0000 0000~~4 give
1111 1010 0000 0000 0000 0000 0000 0000
A.1010 0000 0000 0000 0000 0000 0000 0000~~~4 give
0000 1010 0000 0000 0000 0000 0000 0000
A.1010 0000 0000 0000 0000 0000 0000 0000~~~4 give
1111 1010 0000 0000 0000 0000 0000 000056.
56. Give Iollowing Iragment.
outer:Ior(int i0;i3;i)
inner:Ior(int j0;j3;j)
iI(j~1) break outer;
System.out.println(j"and"i); }
Which will be output?
A.0 and 0 B.0 and 1 C.0 and 2 D.0 and 3
E.1 and 0 F.1 and 1 G.1 and 2 H.1 and 3
I.2 and 0 J.2 and 1 K.2 and 2 L.2 and 3
57.FilterInputStream is the parent class Ior BuIIeredInputStream,
DataInputStream and PrintStream. Which classes are
a valid argument Ior the constructor oI a FilterOutputStream?
A.InputStream B.OutputStream C.File
D.RandomAccessFile E.StreamTokenizer
58.Which is the main()method return?
A.String B.void C.char D.int
59.Look the inheritance ralation:
person
,
, ,
man woman
In a sourse oI java have the Iollowing line: person pnew man();
What statement are corrected?
A.The expression is illegal.
B.Compile corrected but running wrong.
C.The expression is legal.
D.Will construct a person's object.60.
60.Look the inheritance ralation:
person
,
, ,
man woman
In a sourse oI java have the Iollowing line: woman wnew man();
What statement are corrected?
A.The expression is illegal.
B.Compile corrected but running wrong.
C.The expression is legal.
D.Will construct a woman's object.




Basic Java

Q1
Given the following class, which statements can be inserted at position 1
without causing the code to fail compilation?
Public class Test { int a, b=0;
static int c;
public void m()
{ int d;
int e=0;
// Position 1
} }
(a) a++
(b) b++
(c) c++
(d) d++
(e) e++
Q2 hich statement are true concerning the effect of the >> and >>>
operators?
(a) For non-negative values of the left operand, the >> and >>> operators
will have the same effect
(b) The result of (-1 >> 1) is 0
(c) The result of (-1 >>> 1) is 1
(d) The value returned by >>> will never be negative as long as the value
of the right operand is equal to or greater than 1
(e) hen using the >> operator, the leftmost bit of the bit representation of
the resulting value will always as the same bit value as the leftmost bit
of the bit representation of the left operand
Q3 hat is wrong with the following code?
Class MyException extends Exception{}
Public class Test {
public void foo() {
try{ bar(); }
finally { baz(); } catch (MyException e) {} }

public void bar () throws MyException { throw new MyException(); }
public void baz () throws RuntimeException { throw new
RuntimeException(); }

(a) Since the method foo() does not catch the exception generated by the
method baz(), it must declare the RuntimeException in its throws clause
(b) A try block cannot be followed by both a catch and a finally block
(c) An empty catch block is not allowed
(d) A catch block cannot follow a finally block
(e) A finally block must always follow one or more catch blocks
Q4 hat will be written to the standard output when the following program is
run?
Public class Test {
Public static void main(String args [])
{ String word = "restructure;
System.out.println(word.substring(2,3));
} }
(a) est
(b) es
(c) str
(d) st
(e) s
Q5 Given that a static method dot() in a class ork represents work to be
done, what block of code will succeed in starting a new thread that will do
the work?
(a) Runnable r = new Runnable(){ Public void run(){ ork.dot(); } };
Thread t new Thread( r );
t.start();
(b) Thread t new Thread(){ public void start(){ork.dot(); }};
t.start();
(c) Runnable r = new Runnable() { Public void run(){ ork.dot(); } };
r.start();
(d) Thread t new Thread( new ork()) ; t.start();
(e) Runnable t = new Runnable() { Public void run(){ ork.dot(); } }; t.run();
Q6 rite a line of code that declares a variable named layout of type
LayoutManager and initializes it with a new object, which when used with a
container can lay out components in a rectangular grid of equal-sized
rectangles, 3 components wide and 2 components high
(a) LayoutManager layout = new Map(2,3);
(b) LayoutManager layout = new Paint(2,3);
(c) LayoutManager layout = new GridLayout(2,3);
(d) All of the above
Q7 hat will be the result of compiling and running the following code?
Public class Test {
static int a;
int b;
Public Test1
{ nt c;
c = a ;
a++;
b += c;
}
public static void main(String args[] ){ new Test1(); }
}
(a) The code will fail to compile, since the constructor is trying to access
static members
(b) The code will fail to compile, since the constructor is trying to use static
member variable a before it has been initialized
(c) The code will fail to compile, since the constructor is trying to use static
member variable b before it has been initialized
(d) The code will fail to compile, since the constructor is trying to use local
variable c before it has been initialized
(e) The code will compile, and run without any problems.
Q8 hat will be written to the standard output when the following program is
run?
Public class Test{ Public static void main(String args[]) {
System.out.println(9 ^ 2); } }
(a) 81
(b) 7
(c) 11
(d) 0
(e) false
Q9 hich statements are true concerning the default layout manager for
containers in the ava.awt package?
(a) Objects instantiated from Panel do not have a default layout manager
(b) Objects instantiated from Panel have FlowLayout as default layout
manager
(c) Objects instantiated from Applet have BorderLayout as default layout
manager
(d) Objects instantiated from Dialog have BorderLayout as default layout
manager
(e) Objects instantiated from Window have the same default layout
manager as instances of Applet
Q1
0
hich declarations will allow a class to be started as a standalone
program?
(a) Public void main(String args[])
(b) Public void static main(String args[])
(c) Public static main(String[] argv)
(d) Final Public static void main(String[] array)
(e) Public static void main(String args[])
Q11
Under which circumstances will a thread stop?
(a) The method waitford() in class MediaTracker is called
(b) The run() method that the %read is executing ends
(c) The call to the start() method of the %read object returns
(d) The suspend() method is called on the %read object
(e) The wait() method is called on the %read object
Q1
2
hen creating a class that associates a set of keys with a set of values,
which of these interfaces is most applicable?
(a) Collection
(b) Set
(c) Sortedset
(d) Map
Q1
3
hat does the value returned by the method getD() found in class
java.awt.ATEvent uniquely identify?
(a) The particular event instance
(b) The source of the event
(c) The set of events that were triggered by the same action
(d) The type of event
(e) The type of component from which the event originated
Q1
4
hat will be written to the standard output when the following program is
run?
Class Base{
int i;
Base() { Add(1); }
void add(int v) { i += v ;}
void print() { System.out.println(i); }
Class Extension extends Base{
Extensions() { add(2);}
void add (int v) { i += v*2; }
Public class Test{
Public static void main(String args[]) { bogo(new Extension());}
static void bogo(Base b) { b.add(8); b.print(); }
}
(a) 9
(b) 18
(c) 20
(d) 21
(e) 22
Q1
5
hich lines of code are valid declarations of a native method when
occurring within the declaration of the following class?
Public class Test{ // insert declaration of a native method here }
(a) native public void setTemperature(int kelvin);
(b) private native void setTemperature(int kelvin);
(c) protected int native getTemperature();
(d) public abstract native void setTemperature(int kelvin);
(e) native int setTemperature(int kelvin) ()
Q1
6
ow does the weighty property of the ridBagConstraints objects used in
grid bag layout affect the layout of the components?
(a) f affects which grid cell the components end up in
(b) f affects how the extra vertical space is distributed
(c) f affects the alignment of each components
(d) f affects whether the components completely fill their allotted display
area vertically
Q1
7
hich statement can be inserted at the indicated position in the following
code to make the program write 1 on the standard output when run?
Public class Test{
nt a = 1 ;
nt b = 1 ;
nt c = 1 ;
Class nner{
nt a = 2 ;
nt get() {
int c = 3 ;
// insert statement here
return c;
} }
Test () {
nner = new nner()
System.out.println(i.get());
}
public static void main(String args[]){ new Test(); }
}
(a) C = b;
(b) C = this.a;
(c) C = this.b;
(d) C = Test.this.a;
(e) C = c;
Q1
8
hich is the earliest line in the following code after which the object
created on the line marked (0) will be candidate for being garbage
collected assuming no compiler optimizations are done?
Public class Test{
Static String f(){
Static a = "hello;
Static b = "bye ; // (0)
Static c = b + "! ; // (1)
Static d = b ;
b= a; // (2)
d= a; // (3)
return c ; // (4)
}
public static void main(String args[]) {
String msg = f();
System.out.println(msg); // (5)
} }

(a) The line marked (1)
(b) The line marked (2)
(c) The line marked (3)
(d) The line marked (4)
(e) The line marked (5)
Q1
9
hich methods from the String and StringBuffer classes modify the object
on which they are called?
(a) The charAt() method of the String class
(b) The toUpperCase() method of the String class
(c) The replace() method of the String class
(d) The reverse() method of the StringBuffer class
(e) The length() method of the StringBuffer class
Q20
hich statements, when inserted at the indicated position in the following
code, will cause a runtime exception when attempting to run the program?
Class A {}
Class B extends A{}
Class C extends A{}
Public class Test {
Public static void main(String args[]) {
A x = new A();
B y = new B();
C z = new C();
// insert statement here
} }
(a) x = y;
(b) z = x ;
(c) y = (B) x ;
(d) z = (C ) y;
(e) y = (A) y;
Q21
hich of these are keywords in Java?
(a) Default
(b) NULL
(c) String
(d) Throws
(e) Long
Q2
2
t is desirable that a certain method within a certain class only be accessed
by classes that are defined within the same package as the class of the
method. ow can such restrictions be enforced?
(a) Mark the method with the keyword public
(b) Mark the method with the keyword protected
(c) Mark the method with the keyword private
(d) Mark the method with the keyword package
(e) Do not mark the method with any accessibility modifiers
Q2
3
hich code fragments will succeed in initializing a two dimensional array
named tab with a size that will cause the expression tab[3][2] to access a
valid element?
(a) nt[] [] tab = { {0,0,0}, {0,0,0}};
(b) nt tab[] [] = new int[4][]; for(int =0, <tab.length; ++) tab[] = new int[3];
(c) nt tab[][]= {
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0};
(d) nt tab [3][2];
(e) nt [] tab[]= { {0,0,0}, {0,0,0},{0,0,0},{0,0,0}};
Q2
4
hat will be the result of attempting to run the following program?
Public class Test{
Public static void main(String args[])
{ String[][][] arr = { {{},null}, {{ "1,2}, {"1, null, "3}}, {}, { {"1,null} } };
System.out.println (arr.length + arr[1][2].length);
} }
(a) The program will terminate with an ArrayndexOutOfBoundException
(b) The program will terminate with an NullPointerException
(c) 4 will be written to standard output
(d) 6 will be written to standard output
(e) 7 will be written to standard output
Q2
5
hich expressions will evaluate to true if preceded by the following code?
String a = "hello;
String b = new String(a);
String c = a;
Char[] d = {'h','e','l','l','o'};

(a) (a == "ello)
(b) (a == b)
(c) (a == c)
(d) a.equals(b)
(e) a.equals(d)
Q2
6
hich statements concerning the following code are true?
Class A {
public A() {}
public A(int ) { this(); }
}
class B extends A {
public boolean B(String msg) { return false; }
}
class C extends B {
private C() {super (); }
public C(String msg) { this();}
public C(int ) {}
}

(a) The code will fail to compile
(b) The constructor in A that takes an int as an argument will never be
called as a result of constructing an object of class B or C
(c) Class C has three constructors
(d) Objects of class B cannot be constructed
(e) At most one of the constructors of each class is called as a result of
constructing an object of class C
Q2 Given two collection objects referenced by col1 an col2, which of these
7 statements are true?
(a) The operation col1.retainAll(col2) will not modify the col1 object
(b) The operation col1.removeAll(col2) will not modify the col2 object
(c) The operation col1.addAll(col2) will return a new modify collection
object, containing elements from both col1 and col2
(d) The operation col1.containsAll(col2) will not modify the col1 object
Q2
8
hich statements concerning the relations between the following classes
are true?
Class Foo{
nt num;
Baz comp = new Baz();
}
class Bar {
boolean flag ;
}
class Baz extends Foo{
Bar thing = new Bar();
Double limit ;
}
(a) A Bar is a Baz
(b) A Foo has a Bar
(c) A Baz is a Foo
(d) A Foo is a Baz
(e) A Baz has a Bar
Q29
hich statements concerning the value of a member variable are true,
when no explicit assignments have been made?
(a) The value of an int is undetermined
(b) The value of all numeric types is zero
(c) The compiler may issue an error if the variable is used before it is
initialized
(d) The value of a String variable is " (empty string)
(e) The value of all object variables is null
Q30
hich statements describe guaranteed behavior of the garbage collection
and finalization mechanisms?
(a) Objects are deleted when they can no longer be accessed through any
reference
(b) The finalize() method will eventually be called on every object
(c) The finalize() method will never be called more than once on an object
(d) The object will not be garbage collected as long as it is possible for an
active part of the program to access it through a reference
(e) The garbage collector will use a mark and sweep algorithm
Q3
1
hich code fragments will succeed in printing the last argument given on
the command line to the standard output, and exit gracefully with no output
if no arguments are given?
(a) Public static void main(String args[]){
f (args.length!=0)
System.out.println(args[args.length-1]);
}
(b) Public static void main(String args[]) {
Try { System.out.println(args[args.length]) ; }
Catch (ArrayndexOutOfBoundsException e) {}
}
(c) Public static void main(String args[]) {
nt ix = args.length;
String last = args[ix];
f (ix > 0) System.out.println(last);
}
(d) Public static void main(String args[]) {
nt ix = args.length-1;
f (ix > 0) System.out.println(args[ix]);
}
(e) Public static void main(String args[]) {
Try { System.out.println(args[args.length-1]) ; }
Catch (NullPointerException e) {}
}
Q3
2
hich of the following statements concerning the collection interfaces are
true?
(a) $et extends Collection
(b) All methods defined in $et are also defined in Collection
(c) List extends Collection
(d) All method defined in List are also defined in Collection
(e) Map extends Collection
Q3
3
The range of short is
(a) 2
7
to 2
7
1
(b) 2
8
to 2
8

(c) 2
15
to 2
15
-1
(d) 2
16
to 2
16
1
(e) 0 to 2
16
1
Q3
4
hat is the name of the method that threads can use to pause their
execution until signalled to continue by another thread?
(a) ait
(b) Suspend
(c) Stop
(d) All of the above
Q3
5
Given the following class definitions, which expression identifies whether
the object referred to by obj was created by instantiating class B rather
than classes A, C and D?
Class A {}
Class B extends A {}
Class C extends B {}
Class D extends A {}
(a) Obj instanceof B
(b) Obj instanceof A && ! (obj instanceof C)
(c) Obj instanceof B && ! (obj instanceof C)
(d) !(obj instanceof C || obj instanceof D)
(e) !(obj instanceof A) && ! (obj instanceof C) && ! (obj instanceof D)
Q3
6
hat will be written to the standard output when the following program is
run?
Public class Test {
Public static void main(String args[]){
Double d = -2.9;
nt i = (int) d;
i *= (int) Math.ceil(d);
i *= (int) Math.abs(d);
System.out.println(i);
} }
(a) 12
(b) 18
(c) 8
(d) 12
(e) 27
Q3
7
hat will be written to the standard output when the following program is
run
Public class Test{
nt a;
nt b;
Public void f() {
A = 0;
B = 0 ;
nt [] c = { 0 };
G(b,c);
System.out.println(a+ " + b + " " + c[0] + " " );
}
Public void g(int b, int [] c) {
A = 1;
B = 1 ;
C[0] = 1;
}
Public static void main(String args[]) {
Test obj = new Test();
Obj.f();
}
}
(a) 0 0 0
(b) 0 0 1
(c) 0 1 0
(d) 1 0 0
(e) 1 0 1
Q3
8
hich statements concerning the effect of the statement gfx.drawRect
(5,5,10,10) are true, given that gfx is a reference to a valid Graphics
object?
(a) The rectangle drawn will have a total width of 5 pixels
(b) The rectangle drawn will have a total height of 6 pixels
(c) The rectangle drawn will have a total width of 10 pixels
(d) The rectangle drawn will have a total height of 11 pixels
(e) None of the above
Q39
Given the following code, which code fragments, when inserted at the
indicated location, will succeed in making the program display a button
spanning the whole window area?
mport java.awt. ;
Public class Test{
public static void main(String args[]) {
indow win = new Frame();
Button but = new Button("button);
// insert code fragment here
win.setSize(200,200);
win.setVisible(true);
} }
(a) in.setLayout(new BorderLayout());
in.add(but);
(b) in.setLayout(new GridLayout(1,1));
in.add(but);
(c) in.setLayout(new BorderLayout( ));
in.add(but.BorderLayout.CENTER);
(d) in.add(but);
(e) in.setLayout(new FlowLayout());
in.add(but);
Q4
0
hich method implementations will write the given string to a file named
"file, using UTF8 encoding?
(a) Public void write(String msg) throws OException{
Fileriter fw = new Fileriter(new File("file));
Fw.write(msg);
Fw.close();
}
(b) Public void write(String msg) throws OException{
OutputStreamriter osw = new OutputStreamriter(new
FileOutputStream("file), "UTF8);
Osw.write(msg);
Osw.close();
}
(c) Public void write(String msg) throws OException{
Fileriter fw = new Fileriter(new File("file));
Fw.setEncoding("UTF8);
Fw.write(msg);
Fw.close();
}
(d) Public void write(String msg) throws OException{
Filterriter fw = new Filterriter(new Fileriter("file),UTF8);
Fw.write(msg);
Fw.close();
}
(e) Public void write(String msg) throws OException{
OutputStreamriter osw = new OutputStreamriter(new
OutputStream(new File("file)), UTF8);
Osw.write(msg);
Osw.close();
}
Q4
1
hich are the valid identifiers?
(a) _class
(b) $value$
(c) zer@
(d) angstrom
(e) 2much
Q4
2
hat will be the output of attempting to compile and run the following
program?
Public class Test{
Public static void main(String args[]) {
nt counter = 0;
L1:
For(int i = 10; <0;++){
L2:
nt j = 0;
hile(j<10) {
f (j > 1) break L2;
f ( i == j ) {
Counter ++ ;
Continue L1;
}
}
counter - - ;
}
System.out.println(counter);
}
}
(a) The program will fail to compile
(b) The program will not terminate normally
(c) The program will write 10 to the standard output
(d) The program will write 0 to the standard output
(e) The program will write 9 to the standard output
Q4 Given the following definition, which definitions are valid?
3 nterface {
void setValue(int val);
nt getValue(); }
(a) Class A extends {
nt value;
Void setValue(int val) {value = val;}
nt getValue(){return value;} }
(b) nterface B extends {
void increment(); }
(c) Abstract class C implements {
nt getValue(); { return 0; }
Abstract void increment(); }
(d) nterface D implements {
void increment(); }
(e) Class E implements {
nt value ;
Public void setValue(int val) {value = val ;} }
Q4
4
hich statements concerning the methods notify() and notifyAll() are true?
(a) nstances of class Thread have a method called notify()
(b) A call to the method notify() will wake the thread that currently owns the
monitor of the object
(c) The method notify() is synchronized
(d) The method notifyAll() is defined in class Thread
(e) hen there is more than one thread waiting to obtain the monitor of an
object, there is no way to be sure which thread will be notified by the
notify() method
Q4
5
hich statements concerning the correlation between the inner and outer
instances of non-static inner classes are true?
(a) Member variables of the outer instances are always accessible to inner
instances, regardless of their accessibility modifiers
(b) Member variables of the outer instances can never be referred to using
only the variable name within the inner instance
(c) More than one inner instance can be associated with the same outer
instance
(d) All variables from the outer instance that should be accessible in the
inner instance must be declared final
(e) A class that is declared final cannot have any inner classes
Q4
6
hat will be the result of attempting to compile and run the following code?
Public class Test{
Public static void main(String args[]) {
nt = 4;
Float f = 4.3;
Double d = 1.8;
nt c = 0;
f ( == f ) c++;
f ((int) ( f + d )) == ((int) f + (int) d)) c +=2;
System.out.println( c );
} }
(a) The code will fail to compile
(b) 0 will be written to the standard output
(c) 1 will be written to the standard output
(d) 2 will be written to the standard output
(e) 3 will be written to the standard output
Q4
7
hich operators will always evaluate all the operands?
(a) | |
(b) +
(c) &&
(d) ? :
(e) %
Q4
8
hich statements concerning the switc construct are true?
(a) All switc statements must have a default label
(b) There must be exactly one label for each code segment in a switc
statement
(c) The keyword continue can never occur within the body of a switc
statement
(d) No case label may follow a default label within a single switc
statement
(e) A character literal can be used as a value for a case label
Q4
9
hich modifiers and return types would be valid in the declaration of a
working main() method for a Java standalone application?
(a) Private
(b) Final
(c) Static
(d) nt
(e) Abstract
Q50
hat will be the appearance of an applet with the following init() method?
Public void init() { Add(new Button("hello)); }
(a) Nothing appears in the applet
(b) A button will cover the whole area of the object
(c) A button will appear in the top left corner of the applet
(d) A button will appear, centered in the top region of the applet
(e) A button will appear in the center of the applet

Q51
hich statements concerning the event model of the AT are true?
(a) At most one listener of each type can be registered with a component
(b) Mouse motion listeners can be registered on a List instance
(c) There exists a class named ContainerEvent in package ava.awt.event
(d) There exists a class named MouseMotionEvent in package
ava.awt.event
(e) There exists a class named ActionAdapter in package ava.awt.event
Q5
2
hich statements are true, given the code new FileOutputStream("data ,
true) for creating an object of class FileOutputStream?
(a) FileOutputStream has no constructors matching the given arguments
(b) An OException will be thrown if a file named "data already exists
(c) An OException will be thrown if a file named "data does not already
exist
(d) f a file named "data' exists, its contents will be reset and overwritten
(e) f a file named "data' exists, its output will be appended to its current
contents
Q5
3
Given the following code, write a line of code that, when inserted at the
indicated location, will make the overriding method in xtension invoke the
overridden method in class Base on the current object
Class Base{
Public void print() {
System.out.println("base);
} }
Class Extension extends Base{
Public void print() {
System.out.println("extension);
// insert line of implementation ere
} }
public Class Test{
public static void main(String args[]) {
Extension ext = new Extention();
ext.print();
} }
(a) Super.print();
(b) Super.Test();
(c) Ext.print();
(d) None of the above
Q5
4
Given that file is a reference to a File object that represents a directory,
which code fragments will succeed in obtaining a list of the entries in the
directory?
(a) Vector filelist = ((Directory) file).getList();
(b) String[] filelist = file.directory;
(c) Enumeration filelist = file.contents();
(d) String[] filelist = file.list();
(e) Vector filelist = (new Directory(file)).files();
Q5
5
hat will be written to the standard output when the following program is
run?
Public class Test{
Public static void main)String args[]) {
String space = " ";
String composite = space + "hello + space + space ;
Composite.concat("world);
String trimmed = composite.trim();
System.out.println(trimmed.length());
} }
(a) 5
(b) 6
(c) 7
(d) 12
(e) 13

Q5
6
Given the following code, which statement concerning the objects
referenced through the member variables i, j, k are true, given that any
thread may call the methods a, b, c at any time?
Class Counter{
nt v = 0;
Synchronized void inc() { v++; }
Synchronized void dec() { v- -; }
}
public class Test{
Counter , j, k ;
Public synchronized void a() {
i.inc();
System.out.println("a);
i.dec();
}
Public synchronized void b() {
i.inc(); j.inc(); k.inc();
System.out.println("b);
i.dec(); j.dec(); k.dec();
}
Public void c() {
k.inc();
System.out.println("c);
k.dec();
}
}

(a) i.v is guaranteed always to be 0 or 1
(b) j.v is guaranteed always to be 0 or 1
(c) k.v is guaranteed always to be 0 or 1
(d) j.v will always be greater than or equal to k.v at any given time
(e) k.v will always be greater than or equal to j.v at any given time
Q5
7
hich statements concerning casting and conversion are true?
(a) Conversion from int to long does not need a cast
(b) Conversion from byte to sort does not need a cast
(c) Conversion from float to long does not need a cast
(d) Conversion from sort to car does not need a cast
(e) Conversion from boolean to int using a cast is not possible
Q5
8
Given the following code, which method declarations, when inserted at the
indicated position will not cause the program to fail compilation?
Public class Test {
Public ling sum (long a, long b) { return a + b; }
// insert new metod declaration ere
}

(a) Public int sum( int a, int b) { return a + b ; }
(b) Public int sum( long a, long b) { return 0 ; }
(c) Abstract int sum();
(d) Private long sum(long a , long b) {return a + b ; }
(e) Public long sum(long a , int b) {return a + b ; }
Q5
9
The 8859-1-character code for the uppercase letter A is 565. hich of
these code fragments declare and initialize a variable of type char with this
value?
(a) Char ch = 65;
(b) Char ch = '\65';
(c) Char ch = '\0041';;
(d) Char ch = 'A';
(e) Char ch = "A ;
Q6
0
Given the following code, which of these constructors could be added to
the MySubclass without causing a compile time error?
Class MySuper{
nt number ;
MySuper(int i ) {number = i ;}
}
class MySub extends MySuper {
int count;
MySub(int cnt, int sum) {
Super(num);
Count = cnt ;
}
// insert additional constructor ere
}
(a) MySub() { }
(b) MySub( int cnt) { count = cnt; }
(c) MySub( int cnt) { super(); count = cnt; }
(d) MySub( int cnt) { count = cnt; super(cnt); }
(e) MySub( int cnt) { this(cnt , cnt); }
Q61
hich of these statements are true?
(a) A super() or this() call must always be provided explicitly as the first
statement in the body of a constructor
(b) f both a subclass and its superclass do not have any declared
constructors, the implicit default constructor of the subclass will call
super() when run
(c) f neither super() or this() is declared as the first statement in the body
of a constructor, then this() will implicitly be inserted as the first
statement
(d) f super() is the first statement in the body of constructor, then this()
can be declared as the second statement
(e) Calling super() as the first statement in the body of a constructor of a
subclass will always work, since all superclasses have a default
constructor?
Q6
2
hat will the following program print when run?
Public class MyClass {
Public static void main(String args[]) {
B b = new B("Test);
}
}
class A {
A() { this("1, "2);}
A(String s, String t) { this( s + t );}
A(String s) { System.out.println(s);}
}
class B extends A {
B(String s) { System.out.println(s);}
B(String s, String t) { this( t + s + "3 );}
B() {super("4); };
}
(a) t will simply print %est
(b) t will print %est followed by %est
(c) t will print 123 followed by %est
(d) t will print 12 followed by %est
(e) t will print 4 followed by %est
Q6
3
Given the following variable declaration within the definition of an interface
which of these declarations are equivalent to it?
nt answer = 42;
(a) Public static int answer = 42;
(b) Public final int answer = 42;
(c) static final int answer = 42;
(d) Public int answer = 42;
(e) All of the above
Q6
4
hat is wrong, if anything, with the following code?
Abstract class MyClass implements nterface1, nterface2 {
Void f() { } ;
Void g() { } ;
}
interface nterface1 {
int VAL_A = 1 ;
int VAL_B = 2 ;
void f() ;
void g() ;
}
interface nterface2 {
int VAL_B = 3 ;
int VAL_C = 4 ;
void g() ;
void h() ;
}
(a) nterface1 and nterface2 do not match, therefore MyClass cannot
implement them both
(b) MyClass only implements nterface1. mplementation for void h() from
nterface2 is missing
(c) The declarations of void g() in the two interfaces clash
(d) The declarations of int VAL_B in the two interfaces clash
(e) Nothing is wrong in the code, it will compile without errors
Q6
5
Given the following program, which statement is true?
Public class Test {
Public static void main(String args[]){
A[] arrA ;
B[] arrB ;
arrA = new A[10];
arrB = new B[20];
arrA = arrB; // (1)
arrB = (B[]) arrA ; // (2)
arrA = new A[10];
arrB = (B[]) arrA; // (3)
}
}
class A { }
class B extends A { }
(a) The program will fail to compile, owing to the line labeled (1)
(b) The program will throw a lava.lang.ClassCastException at the line
labeled (2)
(c) The program will throw a lava.lang.ClassCastException at the line
labeled (3)
(d) The program will compile and run without problems, even if the (B[])
cast in the lines labeled (2) and (3) were removed
(e) The program will compile and run without problems, but would not do
so if the (B[]) cast in the lines labeled (2) and (3) were removed
Q6 hich is the first line that will cause compilation to fail in the following
6 program?
Class Test {
Public static void main(String args{}){
Test a ;
SubTest b ;
A = new test(); // (1)
B = new SubTest (); // (2)
A = b ; // (3)
B = a ; // (4)
A = new SubTest(); // (5)
B = new Test(); // (6)
}
}
class SubTest extends Test { }
(a) Line labeled (1)
(b) Line labeled (2)
(c) Line labeled (3)
(d) Line labeled (4)
(e) Line labeled (5)
(f) Line labeled (6)
Q6
7
Given three classes A,B and C where B is a subclass of A and C is a
subclass of B, which one of these boolean expressions correctly identifies
when an object o has actually been instantiated from class B as opposed
from A or C?
(a) ( o instanceof B ) && ( !( o instanceof A ))
(b) ( o instanceof B ) && ( !( o instanceof C ))
(c) !(( o instanceof A ) || ( o instanceof B )
(d) ( o instanceof B )
(e) ( o instanceof B ) && !(( o instanceof A )) || (o instanceof C))
Q6
8
hat will be the result of attempting to compile and run the following
program?
Public class Polymorphism {
Public static void main(String args[]) {
A ref1 = new C();
B ref2 = (B) ref1;
System.out.println(ref2.f());
}
}
class A { int f() {return 0; } }
class B extends A { int f() {return 1; } }
class C extends B { int f() {return 2; } }
(a) The program will fail to compile
(b) The program will compile without errors, but will throw a
ClassCastException when run
(c) The program will compile without errors, and print 0 when run
(d) The program will compile without errors, and print 1 when run
(e) The program will compile without errors, and print 2 when run
Q6
9
Given the following code, which statements are true?
Public interface eavenlyBody{ String describe(); }
Class Star implements eveanlyBody{
String starName;
Public String describe() { return "star + starName; }
}
class Planet{
String name;
Star orbiting;
Public String describe() {
Return "planet + name + "orbiting + orbiting.describe();
}
}
(a) The code will fail to compile
(b) The use of aggregation is justified, since planet as-a star
(c) The code will fail to compile if the name starName is replaced with the
name bodyName throughout the $tar class definition
(d) the code will fail to compile if the name starName is replaced with the
name name throughout the $tar class definition
(e) An instance of Planet is a valid instance of a HeavenlyBody
Q7
0
hat will happen if you register more than one ActionListener in a button
component?
(a) The program will fail to compile
(b) The program will issue a runtime exception during execution
(c) All the registered action listeners will be notified when the button is
clicked
(d) The last registered action listeners will be notified when the button is
clicked
(e) The first registered action listeners will be notified when the button is
clicked


A1 A2 A3 A4 A5 A6 A7 A8 A9 A10
A,B,C
,E
A,B,E D E A C E C B,D D,E

A11 A12 A13 A14 A15 A16 A17 A18 A19 A20
B
D D E A,B B A,D C D C

A21 A22 A23 A24 A25 A26 A27 A28 A29 A30
D,E
D,E B,E A C,D B,C B,D C,E B,E C,D

A31 A32 A33 A34 A35 A36 A37 A38 A39 A40
A
A,B,C C A C C E D A,B,C B

A41 A42 A43 A44 A45 A46 A47 A48 A49 A50
A,B,D
A B A,E A,C A B,E E B,C D

A51 A52 A53 A54 A55 A56 A57 A58 A59 A60
B,C E A D A A,B A,B,E A,E D E

A61 A62 A63 A64 A65 A66 A67 A68 A69 A70
B
D E E C D B E B C

Advance JAVA

Q1
JAVA Swing are
(a) Methods
(b) Class
(c) Components
(d) Libraries
Q2 Difference between AT and JFC Classes are:
(a) AT classes are more functional than JFC classes and reside in the
java.awt package
(b) JFC classes are more functional, start with the letter J and reside in the
java.awt.swing package
(c) JFC classes use the AT peer mechanism, start with the letter J and
reside in the java.awt.swing package
(d) None of the above
Q3 The content pane can be accessed by calling :
(a) The getContentPane on Jframe() from JFC
(b) The getFrame() on Frame() class from AT
(c) The textfield on JtextField() from JFC
(d) Cannot be accessed
Q4 To present contents in a Tabbed Pane format :
(a) The TabbedPane class is used
(b) The JtabbedPane class is used
(c) The addTab() method is used
(d) None of the above
Q5 The Jlabel class has properties of:
(a) Displaying text message
(b) con to the text message
(c) Position of the text message and icon
(d) All of the above
Q6 Anonymous inner classes are
(a) A heavyweight listener and is generally avoided
(b) Never used in JAVA programming
(c) A useful way to add a lightweight listener to a component
(d) The class definition begins and ends with {( . )}; combination
Q7 The JtoggleButtons class announces state changes by sending temEvents
to temListenters
(a) True
(b) False
Q8 The Jcheckbox class is similar to JToggleButton
(c) True
(a) False
Q9 The JcomboBox class is like the java.awt.Choice class
(d) True
(a) False
Q1
0
The JSlider class
(a) s unlike the java.awt.Scrollbar class
(b) Enhances the java.awt.Scrollbar class
(c) Both the classes are different in their functionality
(d) None of the above

Q11
The JToolBar class
(a) s a rectangular area that can be detached from the window in which it
resides and placed on the desktop or any other region of the window
(b) Cannot be detached from the window in which it resides
(c) s a rectangular area that cannot contain other components
(d) None the above
Q1
2
JAVA is
(a) A write once run anywhere language
(b) A write once run once compiler
(c) A machine dependent programming language
(d) A write once and compile at runtime language
Q1
3
Java based clients are
(a) eavily dependent on hardware and software maintenance
(b) Expensive software requiring configurations
(c) Thin clients
(d) None of the above
Q1
4
Relational Database Management Systems (RDBMS) has been the
pioneering vision of
(a) Microsoft
(b) BM
(c) Bill Clinton
(d) Dr. E.F Codd
Q1
5
Data stored in RDBMS are retrieved through
(a) Natural Query Language
(b) Structured Query Language (SQL)
(c) Both the above
(d) None of the above
Q1
6
All RDBMS and DBMS systems support SQL to retrieve data
(a) True
(b) False
Q1
7
n a two tier model
(a) The database developer creates an application front-end and access
data through a socket connection to the server
(b) The database developer creates an application front-end and access
data through a socket connection on the same computer
(c) No socket connection is used to access data from the server database
(d) There is no concept of front end and back end database connectivity
Q1
8
The formatting and display of the data is the responsibility of :
(a) Server application
(b) Client application
(c) Third Party vendor
(d) A combination of the above
Q1
9
Macro Programs written for simple data manipulation are called
(a) Applications
(b) Functions
(c) Stored procedures
(d) Packages
Q2
0
________ executes stored procedures automatically when some event
occurs
(a) Remote Procedure Calls
(b) Triggers
(c) Remote Method nvocation
(d) All the above

Q21
Two tier database models have limitations like:
(a) Simple library functions for manipulation of server database
(b) New Versions could be easily incorporated without recompiling or
redistribution
(c) Universal vendor provided libraries
(d) Large client side runtimes applications, driving up the cost
Q2
2
n a three tier database design, the client communicates with:
(a) The database server directly
(b) An intermediate server that provides a layer of abstraction from the
database
(c) Client side libraries for database access
(d) Data reply procedure calls
Q2
3
The JDBC AP is designed to allow developers to:
(a) Create database front ends without having to continually rewrite their
code
(b) Rewrite their code using various vendor developed libraries
(c) Access proprietary third party solutions
(d) Create one time write and forget applications
Q2
4
JDBC provides a multi interfaced AP that is uniform and database
dependent
(a) True
(b) False
Q2
5
The Java interface drivers
(a) Access the database servers for fetching the data from the database
table
(b) Are mapped to the corresponding library routine calls of the database
serer
(c) Take care of the translation of the standard JDBC calls into the specific
calls required by the database it supports
(d) There is no concept of drivers in Java
Q2
6
JDBC is
(a) Derived from Microsoft's Open Database Connectivity specification
(ODBC)
(b) Developed in Java and based on X/Open SQL Command Level
nterface
(c) Non compliant with ODBC drivers
(d) Developed by Microsoft in conjunction with ODBC calls
Q2
7
The JDBC AP has ______________ and _______________ interface
(a) Application Layer and Client Layer
(b) Client Layer and Business Layer
(c) Middleware Layer and Firmware Layer
(d) Application Layer and Driver Layer
Q2
8
The main interfaces for a Driver Layer are:
(a) Driver, Connection, Statement and ResultSet
(b) Application, Connection, Statement and ResultSet
(c) DriverManager, Connection, Statement and ResultSet
(d) ApplicationManager, Connection, Statement and ResultSet
Q2
9
The DriverManager is responsible for:
(a) Loading and unloading drivers, making connection through drivers,
logging and database login timeouts
(b) Loading and making connection through drivers, database login
timeouts
(c) Unloading and disconnecting through drivers, logout and login timeouts
(d) None of the above
Q3
0
Every JDBC program must have at least _______ implementations of the
JDBC driver
(a) 0
(b) 10
(c) 1
(d) 3

Answers:
1 2
3
4 5 6 7 8 9 1
0
C B B D C B

11 12
13
14 15 16 17 18 19 2
0
C D B B C B

21 22
23
24 25 26 27 28 29 3
0
D B B C B D C

1. hich statement are characteristics of the >> and >>> operators.

A. >> performs a shift
B. >> performs a rotate
C. >> performs a signed and >>> performs an
unsigned shift
D. >> performs an unsigned and >>> performs a
signed shift
E. >> should be used on integrals and >>> should
be used on floating point types

C.


2. Given the following declaration

String s = "Example";

hich are legal code?

A. s >>> = 3;
B. s[3] = "x";
C. int i = s.length();
D. String t = "For " + s;
E. s = s + 10;

CDE.


3. Given the following declaration

String s = "hello";

hich are legal code?

A. s >> = 2;
B. char c = s[3];
C. s += "there";
D. int i = s.length();
E. s = s + 3;

CDE.


4. hich statements are true about listeners?

A. The return value from a listener is of boolean
type.
B. Most components allow multiple listeners to be
added.
C. A copy of the original event is passed into a
listener method.
D. f multiple listeners are added to a single
component, they all must all be friends to
each other.
E. f the multiple listeners are added to a single
component, the order [in which listeners
are called is guaranteed].

BC.


5. hat might cause the current thread to stop
executing.

A. An nterruptedException is thrown.
B. The thread executes a wait() call.
C. The thread constructs a new Thread.
D. A thread of higher priority becomes ready.
E. The thread executes a waitforD() call on a
MediaTracker.

ABDE.


6. Given the following incomplete method.

1. public void method(){
2.
3. if (someTestFails()){
4.
5. }
6.
7.}

You want to make this method throw an
OException if, and only if, the method
someTestFails() returns a value of true.
hich changes achieve this?

A. Add at line 2: OException e;
B. Add at line 4: throw e;
C. Add at line 4: throw new OException();
D. Add at line 6: throw new OException();
E. Modify the method declaration to indicate that an
object of [type]
Exception might be thrown.

DE. (E suppose they mean the method declaration
for someTestFails.)


7. hich modifier should be applied to a method for
the lock of the object this to be
obtained prior to executing any of the method
body?

A. final
B. static
C. abstract
D. protected
E. synchronized

E.


8. hich are keywords in Java?

A. NULL
B. true
C. sizeof
D. implements
E. instanceof

DE.


9. Consider the following code:

nteger s = new nteger(9);
nteger t = new nteger(9);
Long u = new Long(9);

hich test would return true?

A. (s==u)
B. (s==t)
C. (s.equals(t))
D. (s.equals(9))
E. (s.equals(new nteger(9))

CE.


10. hy would a responsible Java programmer
want to use a nested class?

Don't know the answers. But here are some
reasons from Exam Cram.

a.To keep the code for a very specialized class in
close association with the class it works with.
b. To support a new user interface that generates
custom events.
c. To impress the boss with his/her knowledge of
Java by using nested classes all over the
place.

AB.


11. You have the following code. hich numbers
will cause "Test2" to be printed?

switch(x){

case 1:
System.out.println("Test1");
case 2:

case 3:
System.out.println("Test2");
break;
}
System.out.println("Test3");
}

A. 0
B. 1
C. 2
D. 3
E. 4

BCD.
11. You have the following code. hich numbers
will cause "Test3" to be printed?

switch(x){

case 1:
System.out.println("Test1");
case 2:

case 3:
System.out.println("Test2");
break;
default:
System.out.println("Test3");
}

A. 1
B. 2
C. 3
D. 4
E. none

D




12. hich statement declares a variable a which is
suitable for referring to an array of 50
string objects?

A. char a[][];
B. String a[];
C. String []a;
D. Object a[50];
E. String a[50);
F. Object a[];

BCF.


13. hat should you use to position a Button within
an application frame so that the
width of the Button is affected by the Frame size
but the height is not affected.

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

E.


14. hat might cause the current thread to stop
executing?

A. An nterruptedException is thrown
B. The thread executes a sleep() call
C. The thread constructs a new Thread
D. A thread of higher priority becomes ready
(runnable)
E. The thread executes a read() call on an
nputStream

ABDE.


Non-runnable states:

* Suspended: caused by suspend(), waits for
resume()
* Sleeping: caused by sleep(), waits for timeout
* Blocked: caused by various /O calls or by failing
to get a monitor's lock, waits for /O or
for the monitor's lock
* aiting: caused by wait(), waits for notify() or
notifyAll()
* Dead: Caused by stop() or returning from run(), no
way out

From Certification Study Guide p. 227


15. Consider the following code:

String s = null;

hich code fragments cause an object of type
NullPointerException to be thrown?

A. if((s!=null) & (s.length()>0))
B. if((s!=null) &&(s.length()>0))
C. if((s==null) | (s.length()==0))
D. if((s==null) || (s.length()==0))

AC.


16. Consider the following code:

String s = null;

hich code fragments cause an object of type
NullPointerException to be thrown?

A. if((s== null) & (s.length()>0))
B. if((s==null) &&(s.length()>0))
C. if((s!=null) | (s.length()==0))
D. if((s!=null) || (s.length()==0))

ABCD.


17. hich statement is true about an inner class?

A. t must be anonymous
B. t can not implement an interface
C. t is only accessible in the enclosing class
D. t can only be instantiated in the enclosing class
E. t can access any final variables in any enclosing
scope.

E.


18. hich statements are true about threads?

A. Threads created from the same class all finish
together
B. A thread can be created only by subclassing
Java.Lang.Thread.
C. nvoking the suspend() stops a thread so that it
cannot be restarted
D. The Java nterpreter's natural exit occurs when
no non daemon threads remain alive
E. Uncoordinated changes to shared data by
multiple threads may result in the data being
read, or left, in an inconsistent state.

DE.


19. Consider the following code:

1. public void method(String s){
2. String a,b;
3. a = new String("ello");
4. b = new String("Goodbye");
5. System.out.println(a + b);
6. a = null;
7. a = b;
8. System.out.println(a + b);
9. }

here is it possible that the garbage collector will
run the first time?

A. Just before line 5
B. Just before line 6
C. Just before line 7
D. Just before line 8
E. Never in this method

C.


20. hich code fragments would correctly identify
the number of arguments passed via
the command line to a Java application, excluding
the name of the class that is being
invoked?

A. int count = args.length;
B. int count = args.length - 1;
C. int count = 0;
while (args[count] != null)
count ++;
D. int count = 0;
while (!(args[count].equals("")))
count ++;

A.


21. hich are keywords in Java?

A. sizeof
B. abstract
C. native
D. NULL
E. BOOLEAN

BC.


22. hich are correct class declarations? Assume
in each case text constitutes the entire
contents of a file called Fred.java on a system with
a case-significant system.

A. public class Fred {
public int x = 0;
public Fred (int x) {
this.x = x;
}
}

B. public class fred {
public int x = 0;
public fred (int x) {
this.x = x;
}
}

C. public class Fred extends MyBaseClass,
MyOtherBaseClass {
public int x = 0;
public Fred (int xval) {
x = xval;
}
}

D. protected class Fred {
private int x = 0;
private Fred (int xval) {
x = xval;
}
}

E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}

AE.

22. hich are correct class declarations? Assume in
each case text constitutes the entire
contents of a file called Fred.java on a system with
a case-significant system.

A. public class Fred {
public int x = 0;
public Fred (int x) {
this.x = x;
}
}

B. public class fred {
public int x = 0;
public fred (int x) {
this.x = x;
}
}

C. public class Fred extends MyBaseClass,
MyOtherBaseClass {
public int x = 0;
public Fred (int xval) {
x = xval;
}
}

D. protected class Fred {
private int x = 0;
private Fred (int xval) {
x = xval;
}
}

E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}

AE.
//Do car in the place of fred


B is wrong because of case-sensitivity. C is wrong
because multiple inheritance is not
supported in Java. D is wrong because a class can
only be public, abstract, final or default
(with no access modifier).


23. hich are correct class declarations? Assume
in each case text constitutes the entire
contents of a file called Test.java on a system with
a case-significant system.

A. public class Test {
public int x = 0;
public Test (int x) {
this.x = x;
}
}

B. public class Test extends MyClass,
MyOtherClass {
public int x = 0;
public Test (int xval) {
x = xval;
}
}

C. import java.awt.*;
public class Test extends Object {
int x;
private Test (int xval) {
x = xval;
}
}


D. protected class Test {
private int x = 0;
private Test (int xval) {
x = xval;
}
}

AC.


24. A class design requires that a particular
member variable must be accesible for direct
access by any subclasses of this class, otherwise
not by classes which are not members
of the same package. hat should be done to
achieve this?

A. The variable should be marked public
B. The variable should be marked private
C. The variable should be marked protected
D. The variable should have no special access
modifier
E. The variable should be marked private and an
accessor method provided

C.


25. hich correctly create an array of five empty
Strings?

A. String a [] = new String [5];
for (int i = 0; i < 5; a[i++] = "");

B. String a [] = {"", "", "", "", "", ""};

C. String a [5];
D. String [5] a;
E. String [] a = new String[5];
for (int i = 0; i < 5; a[i++] = null);

AB.


26. hich cannot be added to a Container?

A. an Applet
B. a Component
C. a Container
D. a Menu
E. a Panel

D.

26. hich cannot be added to a Container?

A. an Applet
B. a Panel
C. a Container
D a Container
E. a Menutem

E.


27. FilterOutputStream is the parent class for
BufferedOutputStream, DataOutputStream
and PrintStream. hich classes are a valid
argument for the constructor of a
FilterOutputStream?

A. nputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer

B.


28. FilternputStream is the parent class for
BufferednputStream and DatanputStream.
hich classes are a valid argument for the
constructor of a FilternputStream?

A. File
B. nputStream
C. OutputStream
D. FilenputStream
E. RandomAccessFile

B.


29. Given the following method body:

{
if (atest()) {
unsafe():
}
else {
safe();
}
}

The method "unsafe" might throw an
ATException (which is not a subclass of
RunTimeException). hich correctly completes the
method of declaration when added at
line one?

A. public ATException methodName()
B. public void methodname()
C. public void methodName() throw ATException
D. public void methodName() throws
ATException
E. public void methodName() throws Exception

DE.


30. Given a TextArea using a proportional pitch font
and constructed like this:

TextField t = new TextArea("12345", 5, 5);

hich statement is true?

A. The displayed width shows exactly five
characters on each line unless otherwise
constrained.
B. The displayed height is five lines unless
otherwise constrained.
C. The maximum number of characters in a line will
be five.
D. The user will be able to edit the character string.
E. The displayed string can use multiple fonts.

BD.


31. Given this skeleton of a class currently under
construction:

public class Example {
int x, y;

public Example(int a){
//lots of complex computation
x = a;
}

public Example(int a, int b) {
/*do everything the same as single argument
version of constructor
including assignment x = a */
y = b;
}
}

hat is the most concise way to code the "do
everything..." part of the constructor
taking two arguments?

Answer:

this(a);


32. Given this skeleton of a class currently under
construction:

public class Example {
int x, y;

public Example(int a, int b){
//lots of complex computation
x = a;
}

public Example(int a, int b, long c) {
/*do everything the same as the two argument
version of constructor
including assignment x = a */
y = b;
}
}

hat is the most concise way to code the "do
everything..." part of the constructor
taking two arguments?

Answer:

this(a, b);

arning! A similar question will appear with at least
two classes, then it is
super("arguments"); that you should use.


33. hich correctly create a two dimensional array
of integers?

A. int a [][] = new int [10,10];
B. int a [10][10] = new int [][];
C. int a [][] = new int [10][10];
D. int []a[] = new int [10][10];
E. int [][]a = new int [10][10];

CDE.


34. Given the following method body:

{
if (sometest()) {
unsafe();
}
else {
safe();
}
}

The method "unsafe" might throw an OException
(which is not a subclass of
RunTimeException). hich correctly completes the
method of declaration when added at
line one?

A. public void methodName() throws Exception
B. public void methodname()
C. public void methodName() throw OException
D. public void methodName() throws OException
E. public OException methodName()

AD.


35. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {
static int x;

public static void main(String args[]){
System.out.println("Value is " + x);
}
}

A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

A.

35. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {
static int[] x = new int[10];

public static void main(String args[]){
System.out.println("Value is " + x[5]);
}
}

A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

A.

36. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {
public int x;

public static void main(String args[]){
System.out.println("Value is " + x);
}
}

A. The output "Value is 0" is printed.
B. Non-static variable x cannot be referenced from
a static context..
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

B.


37. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {


public static void main(String args[]){
int x;
System.out.println("Value is " + x);
}
}

A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

D. Compiler says variable x might not have been
initialized.


38. hat should you use to position a Button within
an application Frame so that the size
of the Button is NOT affected by the Frame size?

A. a FlowLayout
B. a GridLayout
C. the center area of a BorderLayout
D. the East or est area of a BorderLayout
E. The North or South area of a BorderLayout

A.


For the following six questions you will be
presented with a picture in the real test,
showing the relationship and quite long text, but
don't be afraid the questions are quite
easy.


39. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
p = d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

C.

39. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

A methods declares three variables as shown
bellow and assign them non null values.
hich of the following statements is correct for the
following expression?

Parent p;
DerivedOne d1;
DerivedTwo d2;
p = d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

C.

40. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d2 = d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

A.


41. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)d2;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

A. llegal both at compile and runtime. You cannot
assign an object to a sibling reference,
even with casting.


43. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)p;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

B.


44. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = p;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

A.


45. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
p = (Parent)d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

C.


46. hat would you use when you have duplicated
values that needs to be sorted?

A. Map
B. Set
C. Collection
D. List
E. Enumeration

D.


47. hat kind of reader do you use to handle ASC
code?

A. BufferedReader
B. ByteArrayReader
C. Printriter
D. nputStreamReader
E. ?????

D.


nputStreamReader and FileReader automatically
converts from a particular character
encoding to Unicode. From Core Java Advanced
Features p. 820.


48. ow can you implement encapsulation in a
class?

A. Make all variables protected and only allow
access via methods.
B. Make all variables private and only allow access
via methods.
C. Ensure all variables are represented by wrapper
classes.
D. Ensure all variables are accessed through
methods in an ancestor class.

B.


49. hat is the return-type of the methods that
implement the MouseListener interface?

A. boolean
B. Boolean
C. void
D. Pont

C.


50. hat is true about threads that stop executing?

A. hen a running thread's suspend() method is
called, then it is indefinitely possible for
the thread to start.
B. The interpreter stops when the main method
stops.
C. A thread can stop executing when another
thread is in a runnable state.
D. ......
E. ......

C. {t is doubtable answer it might be A}


51. For which of the following code will produce
"test" as output on the screen?

A. int x=10.0;
if (x=10.0)
{
System.out.println("test");
}

B. int x=012;
if (x=10.0)
{
System.out.println("test");
}

C. int x=10f;
if (x=10.0)
{
System.out.println("test");
}

D. int x=10L;
if (x=10.0)
{
System.out.println("test");
}

B.


52. Given this class ?

class Loop {
public static void main (String [] args){
int x=0;
int y=0,
outer: for (x=0; x<100;x++) {
middle: for (y=0;y<100y++) {

System.out.printl("x=" + x + "; y=" + y);

if (y==10){

<<<>>>}
}
}
}//main
}//class

The question is which code must replace the
<<<>>> to finish the outer loop?
A. continue middle;
B. break outer;
C. break middle;
D. continue outer;
E. none of these...

B.


53. hat does it mean when the handleEvent()
returns the true boolean?

A. The event will be handled by the component.
B. The action() method will handle the event.
C. The event will be handled by the
super.handleEvent().
D. Do nothing.

A.


54. hat is the target in an Event?

A. The Object() where the event came from.
B. The Object() where the event is destined for.
C. hat the Object() that generated the event was
doing.

A.


55. hat is the statement to assign a unicode
constant CODE with 0x30a0?

Answer:

public static final char CODE='\u30a0';



56. The following code resides in the source?

class StringTest {

public static void main (String [] args){
//
// String comparing
//
String a,b;
StringBuffer c,d;
c = new StringBuffer ("ello");
a = new String("ello");
b = a;
d = c;

if (<<>>) {}
}
}//class

hich of the following statement return true for the
<<>> line in StringTest.class?

A. b.equals(a)
B. b==a
C. d==c
D. d.equals(c)

ABCD.


57. hich are valid identifiers?

A. %fred
B. *fred
C. thisfred
D. 2fred
E. fred

CE.

57. hich are valid identifiers?

A. Employee
B. _Employee
C. %something
D. *something
E. thisemployee

A.B.E.

58. e have the following class X.

public class X {

public void method();

}

<<>>

hich of the following statement return true for the
<<>> line in StringTest.class?

A. abstract void method() ;
B. class Y extends X {}
C. package java.util;
D. abstract class z { }

BD.


59. hich code fragments would correctly identify
the number of arguments passed via
the command line to a Java Application?

A. int count = args.length;
B. int count = 0;
while args[count] !=null)
count++;
C. int count = 0;
while (!(args[count].equals("")))
count++;
D. int count = args.length - 1;

A.


60. Given a TextField that is constructed like this:

TextField t = new TextField(30);

hich statement is true?

A. The displayed width is 30 columns.
B. The displayed string can use multiple fonts.
C. The user will be able to edit the character string.
D. The displayed line will show exactly thirty
characters.
E. The maximum number of characters in a line will
be thirty.

AC.


61. hat does the java runtime option -cs do?

A. check source with debug report
B. clear classes that are existing when starting
compilation.
C. check if the source is newer when loading
classes.

C.


62. hen is an action invoked?

A. TextField Enter
B. TextArea Enter
C. Scrollbar
D. MouseDown
E. Button

AE.


63. hat error does the following code generate?

class SuperClass{

SuperClass(String s){}
}

class SubClass extends SuperClass{
SubClass(){}
}

......

SubClass s1 = new SubClass("The");
SuperClass s = new SubClass("The");

A. java.lang.ClassCastException
B. rong number of arguments in constructor
C. ncompatible type for =. Can't convert SubClass
to SuperClass.
D. No constructor matching SuperClass found in
class SuperClass.

BD.


64. ow do you declare a native method called
myMethod in Java?

Answer:

public native void myMethod();


65. hat should you use to position a component
within an application frame so that the
components height is affected by the Framesize?

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

D. C.


66. hat should you use to position a component
within an application frame so that the
components width is affected by the Framesize?

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

E.C.


67. hat should you use to position a Button within
an application frame so that the
height of the Button is affected by the Frame size
but the width is not affected.

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

D.


68. hich are keywords in Java?

A. NULL
B. sizeof
C. friend
D. extends
E. synchronized

DE.


69. hich is the advantage of encapsulation?

A. Only public methods are needed.
B. No exceptions need to be thrown from any
method.
C. Making the class final causes no consequential
changes to other code.
D. t changes the implementation without changing
the interface and causes no
consequential changes to other code.
E. t changes the interface without changing the
implementation and causes no
consequential changes to other code.

D.


70. hat can contain objects that have a unique
key field of String type, if it is required
to retrieve the objects using that key field as an
index?

A. Map
B. Set
C. List
D. Collection
E. Enumeration

A.


71. hich statement is true about a non-static inner
class?

A. t must implement an interface.
B. t is accessible from any other class.
C. t can only be instantiated in the enclosing class.
D. t must be final if it is declared in a method
scope.
E. t can access private instance variables in the
enclosing object.

E.


72. hich declares an abstract method in an
abstract Java class?

A. public abstract method();
B. public abstract void method();
C. public void abstract Method(};
D. public void method() {abstract;/}
E. public abstract void method() {/}
F. public void abstract Method();


B.

73. hich statements on the<<< call>>> line are
valid expressions?

public class SuperClass {
public int x;
int y;
public void m(int a) {}
Superclass(){ }
}
class SubClass extends SuperClass{
private float f;
void m2() { return; }
SubClass() { }
}
class T {
public static void main (String [] args) {
int i;
float g;
SubClass b = SubClass();
<<< calls >>>
}
}

A. b.m2();
B. g=b.f;
C. i=b.x;
D. i=b.y;
E. b.m(6);

ACDE.


74. Type 7 in hexadecimal form.

Answer:

0x7


75. Type 7 in octal form.

Answer:

07


76. hat is the range of an integer?

A. -128127
B. -32 768 32 767
C. -231 231 -1
D. -232 232 -1

C.


77. hat is the range of a char?

A. '\u0000' '\uFFFF'
B. -32 768 32 767
C. -128 127
D. -231 231 -1

A.


78. hat is the range of a char?

A. 0 215-1
B. -32 768 32 767
C. - 2 16 216-1
D. 0 216-1

D.

78. hat is the range of a char?

A. 0 216-1
B. 0 232 -1
C. - 2 16 216-1
D. 0 216-1

D.



79. hich method contains the code-body of a
thread?

A. start()
B. run()
C. init()
D. suspend()
E. continue()

B.


80. hat can you place first in this file?

//hat can you put here?

public class Apa{}

A. class a implements Apa
B. protected class B {}
C. private abstract class{}
D. import java.awt.*;
E. package dum.util;
F. private int super = 1000;

ADE.


81. hat is the output of the following code?

outer: for(int i=1; i<3; i++){
inner: for(int j=1; j<3; j++){
if (j==2){
continue outer;
}
System.out.println(i+" and "+j);
}
}

A. 1 and 1
B. 1 and 2
C. 2 and 1
D. 2 and 2
E. 2 and 3
F. 3 and 2
G. 3 and 3

AC.


82. hat is the output of the following code?

outer: for(int i=1; i<2; i++){
inner: for(int j=1; j<2; j++){
if (j==2){
continue outer;
}
System.out.println(i " and " j);
}
}

A. 1 and 1
B. 1 and 2
C. 2 and 1
D. 2 and 2
E. 2 and 3
F. 3 and 2
G. 3 and 3

A.

82. hat is the output of the following code?

outer: for(int x=0; i<2; x++){
inner: for(int a=0; a<2; a++){
if (a==1){
continue outer;
}
System.out.println(a +" and "+x);
}
}

A. 0 and 0
B. 0 and 1
C. 2 and 1
D. 1 and 2
E. 1 and 2
F. 2 and 1
G. 1 and 3

A.B.


83. ow do you declare a native method?

A. public native method();
B. public native void method();
C. public void native method();
D. public void native() {}
E. public native void method() {}

B.


84. Given the following code, what is the output
when a exception other than a
NullPointerException is thrown?

try{

//some code
}
catch(NullPointerException e) {
System.out.println("thrown 1");
}
finally {
System.out.println("thrown 2");
}
System.out.println("thrown 3");


A thrown 1
B thrown 2
C thrown 3
D none

B.


85. You have been given a design document for a
employee system for implementation in
Java. t states.
bla bla bla

choose between the following words:

public
class
object
extends
Employee
Person
plus at least five more

ow should you name the class?

Answer:

public class Employee extends Person


86. You have been given a design document for a
polygon system for implementation in
Java. t states.

A polygon is drawable, is a shape. You must
access it. t should have values in a vector
bla bla

hich variables should you use?

choose between the following words:

public
object
vector
drawable
color
plus some more

Answer:

vector, color (not sure)


87. You have been given a design document for a
polygon system for implementation in
Java. t states. A polygon is a Shape. You must
access it. t has a vector and corners bla
bla

choose between the following words: hat will you
write when defining the class?

public
class
Polygon
object
extends
Shape
plus some more

Answer:

public class Polygon extends Shape


88. hat is true about the garbage collection?

A. The garbage collector is very unpredictable.
B. The garbage collector is predictable.
C.
D.
E.

A.


87. hat is true about a thread?

A The only way you can create a thread is to
subclass java.lang.Thread
B f a Thread with higher priority than the currently
running thread is created, the thread
with the higher priority runs.
C.
D.
E.

B (not sure)


88. hat happens when you compile the following
code?

public classTest {

public static void main(String args[] ) {
int x;
System.out.println(x);
}

A. Error at compile time. Malformed main method
B. Clean compile
C. Compiles but error at runtime. X is not initialized
D.
E. Compile error. Variable x may not have been
initialized.

E.


89.hat happens hen you run the following
program with the command:

java Prog cat dog mouse

public class Prog {

public static void main(String args[]) {
System.out.println(args[0]) ;
}

A. Error at compile time.
ArrayndexOutOfBoundsException thrown
B. Compile with no output
C. Compile and output of dog
D. Compile and output of cat
E. Compile and output of mouse

D.
89.hat happens hen you run the following program
with the command:

java Prog cat

public class Prog {

public static void main(String args[]) {
System.out.println(args[0]) ;
}

A. Error at compile time.
ArrayndexOutOfBoundsException thrown
B. Compile with no output
C. Compile and output of dog
D. Compile and output of cat
E. Compile and output of mouse

D.


90. hich number for the argument must you use
for the code to print cat?

ith the command:

java Prog dog cat mouse

public class Prog {

public static void main(String args[]) {
System.out.println(args[?]) ;
}
}

A. 0
B. 1
C. 2
D. 3
E. none of these

B.


91. hich number for the argument must you use
for the code to print cat?
ith the command:

java Prog cat dog mouse

public class Prog {

public static void main(String args[]) {
System.out.println(args[?]) ;
}
}

A. 0
B. 1
C. 2
D. 3
E. none of these

A.


92. You have the following code:

.......
String s;
s = "ello";
t = " " + "my";
s.append(t);
s.toLowerCase();
s+= " friend";
System.out.println(s);

hat will be printed?

Answer:

hello my friend


93. hat will happen when you attempt to compile
and run this code?

public class MySwitch{

public static void main(String argv[]) {
MySwitch ms = new MySwitch();
ms.amethod();
}

public void amethod() {

char k=10;

switch(k){
default:
System.out.println("This is the default output");

break;
case 10:
System.out.println("ten");
break;
case 20:
System.out.println("twenty");
break;
}
}
}

A. None of these options
B. Compile time error target of switch must be an
integral type
C. Compile and run with output "This is the default
output"
D. Compile and run with output "ten"

D.


94. hat will happen when you attempt to compile
and run the following code?

public class MySwitch{

public static void main(String argv[]) {
MySwitch ms = new MySwitch();
ms.amethod();
}

public void amethod() {

int k=10;
switch (k){
default: //Put the default at the bottom, not here
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
case 20:
System.out.println("twenty");
break;
}
}
}

A. None of these options
B. Compile time error target of switch must be an
integral type
C. Compile and run with output "This is the default
output
D. Compile and run with output "ten"

A.


95. hich of the following statements are true?
A. For a given component, events will be processed
in the order that the listeners were
added
B. Using the Adapter approach to event handling
means creating blank method bodies for
all event methods
C. A component may have multiple listeners
associated with it
D. Listeners may be removed once added

CD.


Button for instance has the methods
addActionListener (ActionListener a) and
removeActionListener(ActionListener a).


96. hich of the following statements are true?
A. Directly subclassing Thread gives you access to
more functionality of the Java
threading capability than using the Runnable
interface
B. Using the Runnable interface means you do not
have to create an instance of the
Thread class and can call run directly
C. Both using the Runnable interface and
subclassing of Thread require calling start to
begin execution of a Thread
D. The Runnable interface requires only one
method to be implemented, this method is
called run

CD.


97. f you want subclasses to access, but not to override a superclass member
method,
what keyword should precede the name of the superclass
method?

Answer:

final


98. f you want a member variable to not be
accessible outside the current class at all,
what keyword should precede the name of the
variable when declaring it?

Answer:

private


99. hich of the following are correct methods for
initializing the array "dayhigh" with 7
values?

A. int dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
B. int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };
C. int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
D. int dayhigh [] = new int [24, 23, 24, 25, 25, 23,
21];
E. int dayhigh = new [24, 23, 24, 25, 25, 23, 21] ;

BC.


100. Assume that val bas been defined as an int for
the code below.

if(val > 4){
System.out.println("Test A");
}

else if(val > 9){
System.out.println("Test B");
}
else System.out.println("Test C");

hich values of val will result in "Test C" being
printed:
A. val < 0
B val between 0 and 4
C val between 4 and 9
D val > 9
E val = 0
F no values for val will be satisfactory

ABE.

100. Assume that val bas been defined as an int for
the code below.

if(val > 4){
System.out.println("Test A");
}

else if(val > 9){
System.out.println("Test B");
}
else System.out.println("Test C");

hich values of val will result in "Test C" being
printed:
A. val < 0
B val between 0 and 4
C val between 4 and 9
D val > 9
E val = 10 or morethen 10
F no values for val will be satisfactory

AB

101. Consider the code below.

void myMethod(){
try{
fragile() ;
}
catch(NullPointerException npex){

System.out.println("NullPointerException thrown ");
)
catch(Exception ex){
System.out.println("Exception thrown ");
}
finally{
System.out.println("Done with exceptions ");
}
System.out.println("myMethod is done");
}

hat is printed to standard output if fragile() throws
an llegalArgumentException?

A. "NullPointerException thrown"
B. "Exception thrown"
C. "Done with exceptions"
D. "myMethod is done"
E. Nothing is printed

BCD.


102. A class design requires that a particular
member variable must be accessible for
direct access by classes which are members of the
same package. hat should be done
to achieve this?

A. The variable should be marked public
B. The variable should be marked private
C. The variable should be marked protected
D. The variable should have no special access
modifier
E. The variable should be marked private and an
accessor method provided

D.


103. hich method do you call to run a Thread?

A. start()
B. init()
C. begin()
D. run()

A.


104. hich statements on the <<< call >>> line are
valid expressions?

public class SuperClass {

public int x;
int y;
public void m1( int a ) {
}

SuperClass( ) {
}
}

class SubClass extends SuperClass {

private float f;
void m2(int c) {
int x;
return;
}
SubClass() {
}
}

class T {

public static void main( String [] args) {
int i;
float g;
SubClass b = new SubClass( );
<<< calls >>>
}
}


A. b.m2();
B. g=b.f;
C. =b.x;
D. =b.y;
E. b.m1(6);
F. g=b.x;

testa.


105. hat is the range of a byte?

A. -128127
B. -32 768 32 767
C. -231 231 -1
D. -232 232 -1

A.


106. hat is the range of a byte?

A. -27 27 -1
B. -2 15 215 -1
C. -231 231 -1
D. -263 263 -1

A.


107. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {
public static void main (String args[]) {
int x[] = new int[10];
System.out.println("Value is " + x[5]);
}
}

A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

A.


108. hich interface should you use if you want no
duplicates, no order and no particular
retrieval system?

A. Map
B. Set
C. List
D. Collection
E. Enumeration

B.


109. hich are keywords in Java?

A. NULL
B. TRUE
C. sizeof
D. implements
E. synchronized

DE.


110. Consider the code fragment below:

outer: for(int i=0; i < 2; i++){
inner: for(j = 0; j < 2; j++){
if(j==1)
continue outer;
System.out.println("i = " + i ", j = " + j);
}}

hich of the following will be printed to standard
output?

A. i = 0, j = 0
B. i = 1, j = 0
C. i = 2, j = 0
D. i = 0, j = 1
E. i = 1, j = 1
F. i = 2, j = 1
G. i = 0, j = 2
. i = 1, j = 2
. i = 2, j = 2

AB.


111. Consider the code fragment below:


outer: for(int i=1; i < 3; i++){
inner: for(j = 1; j < 3; j++){
if(j==2)
continue outer;
System.out.println("i = " + i ", j = " + j);
}}

hich of the following will be printed to standard
output?

A. i = 1, j = 1
B. i = 1, j = 2
C. i = 1, j = 3
D. i = 2, j = 1
E. i = 2, j = 2
F. i = 2, j = 3
G. i = 3, j = 1
. i = 3, j = 2

AD.


112. hat is the modifier for events in
EventListeners?

A. public
B. none
C. private
D. .....

B.


113. You want the program to print 3 to the output.
hich of the following values for x
will do this?

Code:

switch(x){

case(1):
System.out.println("1");
case(2):
case(3):
System.out.println("2");
default:
System.out.println("3");
}

A 1
B 2
C 3
D 4

ABCD.


114. You want the program to print 3 to the output.
hich of the following values for x
will do this?

Code:

switch(x){

case(1):
System.out.println("1");
case(2):
case(3):
System.out.println("3");
break;
default:
System.out.println("Default");
}

A 1
B 2
C 3
D 4

ABC.


115. A question about the GridbagLayout. One
alternative.

116. You have been given a design document for
an employee system for implementation
in Java. t states.

An Employee has a vector of bla bla, dates for
meetings, number of dependants (what is
this???)

A. Vector
B. nt
C. Date
D. Object
E. New employee e;

hich variables should you use?

Answer:

A, B, C. (Not sure. Don't remember exactly how the
question was posed)


117. You have been given a design document for a
polygon system for implementation in
Java. t states. A polygon is drawable. You must
access it. t has a vector and corners
bla bla

choose between the following words: hat will you
write when defining the class?

public
class
Polygon object
extends
Shape
drawable
plus some more

Answer:

public class Polygon implements drawable


118. A question about stacks. Only one correct
answer.

A. (s it possible to have stack objects in a String)
Code contained + "" + stack2 + "" +
B. (s it possible to write stack1 = stack2;)
C. Prints bla bla bla
D. Prints bla bla
E. Prints bla bla


119. Threads: hich statements are true about
threads stopping to execute?

A. All threads in the same class stop at the same
time
B. The suspend() method stops the thread so that
you can not start it again
C.
D.

C or D.


120. hich statements are true about garbage
collection?
A. Garbage collection is predictable.
B. You can mark a variable or an object, (telling the
system) so that it can be garbage
collected
C. .....
D. .....

C or D.(not sure)


121. Consider the following code. hat will be on
the output. No Exception is thrown.

public class Mock2ExceptionTest{

public static void main(String [] args){

Mock2ExceptionTest e = new
Mock2ExceptionTest();
e.trythis();
}

public void trythis(){

try{

System.out.println("1");
problem();
System.out.println("1b");
}

catch(Exception x){
System.out.println("3");

}

finally{
System.out.println("4");

}
System.out.println("5");
}


public void problem()throws Exception{

//throw not any Exception();
}
}

A. 1
B 1b
C. 3
D. 4
E. 5

ABDE.


No exception is thrown and everything except 3 will
be printed.


121b. Consider the following code. hat will be on
the output. No Exception is thrown.

public class Mock3ExceptionTest{

public static void main(String [] args){

Mock3ExceptionTest e = new
Mock3ExceptionTest();
e.trythis();
}

public void trythis(){

try{

System.out.println("1");
problem();
System.out.println("1b");
}

catch(Exception x){
System.out.println("3");

}

finally{
System.out.println("4");

}
System.out.println("5");
}


public void problem()throws Exception{

throw new Exception();
}
}

A. 1
B 1b
C. 3
D. 4
E. 5

ACDE.


122. hat can you put where the X is?

X

Public class A{}

A. import java.awt.*;
B. package bla.bla;
C. class bla{}
D. public abstract final method();
E. public final int x = 1000;

ABC.


123. hat are the characteristics of a totally
encapsulated class? One answer.

A. methods not private
B. variables not public
C. ......
D. all modifying of the object should be made
through methods

D.


124. Consider the following code:

public class TBMock1{

public static void main(String[]args){

nteger n = new nteger(7);
nteger k = new nteger(7);
Long i = new Long(7);
}
}

hich return true?

A. n==i

B. n==k

C. n.equals(k)

D. n.equals(7)

E. n.equals(new nteger(7))

CE.


125. rite 7 in hexadecimal. Do not use more than
four characters and do no assignment.

Answer:

0x7, 0x07


126. Consider the classes defined below:

import java.io.*;

class Super{

void method (int x, int b)
}

class Sub extends Super{}

ow will a correct method in Sub look like?

A. int method(int x, int b)
B. void method (int x) throws Exception
C. void anotherMethod(int x)
D. ........

BC.


127. Consider the classes defined below:

import java.io.*;

class Super{

int method1 (int x, long b) throws OException
{//code }
}

public class Sub extends Super{}

hich of the following are legal method
declarations to add to the class Sub? Assume that
each method is the only one being added.

A. public static void main (String args[]){}
B. float method2(){}
C. long method1 (int c, long d) {}
D. int method1(int c, long d) throws
ArithmeticException{}
E. int method1 (int c, long d) throws
FileNotFoundException{}

ABE.


128. hat does the method getD do?

A. returns a value which shows the nature of the
event
B. .......
C. ...
D. .....

A.


129. hich object will be created when you
implement a KeyListener? Unsure about how
the question was formulated!!

Answer:

Answered KeyEvent


130 hich of these will create an array that can be
used for 50 Strings?

A. char a[][]
B. String a[]
C. String[]a;
D. String a[5];
E. ...

BC. (not sure)


131 ow can you declare a legal inner class?

A class x{}
B
C mynterface (String x){
D mynterface () {


132. One Superclass and one Subclass. One was
public and one was default. ow do you
create a new instance?? Unsure of the formulation
of the question.

A. new nner()
B. new Outer().new nner()
C. .....
D. ......

B.


133. Claims about adapters and listeners


134. hich are legal identifiers

A. nicedentifier
B. 2Goodbajs
C. %hejpdig
D. _goddag
E. ello2

ADE.


135. hich statement is true about a non-static
inner class?

A. t must implement an interface.
B. t is accessible from any other class.
C. t can only be instantiated in the enclosing class.
D. t must be final if it is declared in a method
scope.
E. t can access any final variables in the enclosing
class

E.


136. A question with some wrong code. hat must
you do to correct. changed to the
static modifier.


137. Consider the following code:

String s = "Svenne";
int i = 1;

hat can you do?

A String t = s>>i;
B Long x = 12;
String s = s + x;
C. .....
D. ......

B.


138. Assume that val has been defined as an int for
the code below.

if(val > 4){
System.out.println("Test A");
}

else if(val > 9){
System.out.println("Test B");
}
else System.out.println("Test C");

hich values of val will result in "Test C" being
printed:
A. val < 0
B val between 0 and 4
C val between 4 and 9
D val > 9
E val = 10
F no values for val will be satisfactory

AB.


139. You are going to read some rows one by one
from a file that is stored locally on your
hard drive. ow do you do it?

A. BufferedReader
B. nputStreamReader
C. One reader with "8859-1" as an argument
D. Don't remember
E. FileReader

E. (Don't remember if E was an alternative.)


140. hat is a correct argument list for a public
static void main method?

A. (String argv [])
B. (String arg )
C. (String [] fish)
D. (String args)
E. (String args{})

Made up alternatives C-E by myself.

AC.


141. Consider the following code:

hat will be printed?

public class AB{

public static void main (String[] args){

int x = 1;

if (0 < x--){

System.out.println(x);
}
}

A. 0
B. 1
C. 2
D. Nothing
E. An llegalArgumentException will be thrown

A.


141b. Consider the following code:

hat will be printed?

public class AB{

public static void main (String[] args){

int x = 1;

if (0 < x--){

System.out.println(x);
}
}

A. 0
B. 1
C. 2
D. Nothing
E. An llegalArgumentException will be thrown

D.


142. hich of the following are valid definitions of
an application's main ( ) method?

A. public static void main( );
B. public static void main( String args );
C. public static void main( String args [] );
D. public static void main( Graphics g );
E. public static boolean main( String args [] );

C.


143. hich of the following are Java keywords?

A array
B boolean
C nteger
D protect
E super

BE.


144. After the declaration:

char[] c = new char[100];

what is the value of c[50]?

A. 50
B. 49
C. '\u0000'
D. '\u0020'
E. ""
F. cannot be determined
G. always null until a value is assigned

C.


145. hich identifiers are valid?

A. _xpoints
B. U2
C. blabla$
D set-flow
E. something

ABCE.


146. Represent the number 6 as a hexadecimal
literal.

Answer:

0x6, 0x06, 0X6, 0X06


147. hich of the following statements assigns
"ello Java" to the String variable s?

A. String s = "ello Java";
B. String s [] = "ello Java";
C. new String s = "ello Java";
D. String s = new String ("ello Java");

AD.


148. An integer, x has a binary value (using 1 byte)
of 10011100. hat is the binary value
of z after these statements:

int y = 1 << 7 ;
int z = x & y;

A. 1000 0001
B. 1000 0000
C. 0000 0001
D. 1001 1101
E. 1001 1100

B.


149. The statement ...

String s = "ello" + "Java";

yields the same value for s as ...

String s = "ello";
String s2 = "Java";
s.concat( s2 );

A. True
B. False

B.


150. f you compile and execute an application with
the following code in its
main()method:

String s = new String("Computer");

if ( s == "Computer" )
System.out.println ("Equal A");
if( s.equals( "Computer" ) )
System.out.println ("Equal B");

A. t will not compile because the String class does
not support the = = operator.
B. t will compile and run, but nothing is printed.
C. "Equal A" is the only thing that is printed.
D. "Equal B" is the only thing that is printed.
E. Both "Equal A" and "Equal B" are printed.

D.


151. Given the variable declarations below:

byte myByte;
int mynt;
long myLong;
char myChar;
float myFloat;
double myDouble;

hich one of the following assignments would need
an explicit cast?

A. mynt = myByte;
B. mynt = myLong;
C. myByte = 3;
D. mynt = myChar;
E. myFloat = myDouble;
F. myFloat = 3;
G. my Double = 3.0;

BE.


152. Consider this class example:

class MyPoint {
void myMethod(){
int x, y;
x = 5; y = 3;
System.out.print("(" + x + ", " + y + ")");
switchCoords(x,y);
System.out.print("(" + x + ", " + y + ")");
}

void switchCoords(int x,int y){
int temp;
temp = x;
x = y;
y = temp;
System.out.print("(" + x + ", " + y + ")");
}
}

hat is printed to standard output if myMethod() is
executed?

A. (5, 3) (5, 3) (5, 3)
B. (5, 3) (3, 5) (3, 5)
C. (5, 3) (3, 5) (5, 3)

C.


153. To declare an array of 31 floating point
numbers representing snowfall for each day
of March in Gnome, Alaska, which declarations
would be valid?

A. double snow[] = new double[31];
B. double snow[31] = new array[31];
C. double snow[31] = new array;
D. double[] snow = new double[31];

AD.


154. f arr[] contains only positive integer values,
what does this function do?

public int guesshat(int arr[]){
int x = 0;
for(int i = 0; i < arr.length; i++)
x = x < arr[i] ? arr[i] : x;
return x;
}

A. Returns the index of the highest element in the
array
B. Returns true/false if there are any elements that
repeat in the array
C. Returns how many even numbers are in the
array
D. Returns the highest element in the array
E. Returns the number of question marks in the
array

D.


155. Consider the code below:

arr[0] = new int[4];
arr[1] = new int[3];
arr[2] = new int[2];
arr[3] = new int[l];
for(int n = 0; n < 4; n++)
System.out.println ( /*hat will work here? */);

hich statement below, when inserted as the body
of the for loop, would print the
number of values in each row?

A. arr[n].length();
B. arr.size;
C. arr.size -1;
D. arr[n] [size] ;
E. arr[n].length;

E.


156. hich of the following are legal declarations of
a two-dimensional array of integers?

A. int[5][5] a = new int[][];
B. int a = new int[5,5];
C. int[]a[] = new int [5][5];
D. int[][]a = new [5]int[5];

C.


157. Given the variables defined below:

int one = 1;
int two = 2;
char initial = '2';
boolean flag = true;

hich of the following are valid?
A. if ( one ){}
B. if( one = two ){}
C. if( one == two ) {}
D. if( flag ){}
E. switch ( one ) { }
F. switch ( flag ) { }
G. switch ( initial ) { }

CDEG.


158. f val = 1 in the code below:

switch (val){
case 1: System.out.println("P");
case 2:
case 3: System.out.println("Q") ;
break;
case 4: System.out.println("R");
default: System.out.println ("S");
}

A. P
B. Q
C. R
D. S

AB.


159. hat exception might a wait() method throw?

Answer:

nterruptedException


160. For the code:

m = 0;
while( m++ < 2 )
System.out.println(m);

hich of the following are printed to standard
output?

A. 0
B. 1
C. 2
D. 3
E. Nothing and an exception is thrown

BC.


161. For the code:

m = 0;
while( ++m < 2 )
System.out.println(m);

hich of the following are printed to standard
output?

A. 0
B. 1
C. 2
D. 3
E. Nothing and an exception is thrown

B.


162. Consider the following code sample:

class Tree{}
class Pine extends Tree{}
class Oak extends Tree{}
public class Forest {
public static void main (String [] args){
Tree tree = new Pine():

if( tree instanceof Pine )
System.out.println ("Pine");

if( tree instanceof Tree )
System.out.println ("Tree");

if( tree instanceof Oak )
System.out.println ( "Oak" );

else
System.out.println ("Oops ");
}
}

Select all choices that will be printed:

A. Pine
B. Tree
C. Forest
D. Oops
E. Nothing will be printed

ABD.


163. hich of the following statements about
Java's garbage collection are true?

A. The garbage collector can be invoked explicitly
using a Runtime object.
B. The finalize method is always called before an
object is garbage collected.
C. Any class that includes a finalize method should
invoke its superclass' finalize method.
D. Garbage collection behaviour is very predictable.

BC.


164. hat line of code would begin execution of a
thread named myThread?

Answer:

myThread.start();


165. hich methods are required to implement the
interface Runnable?

A. wait()
B. run()
C. stop()
D. update()
E. resume()

B.


166. hat class defines the wait() method?

Answer:

Object.

for yield(), sleep(#), start(), run() it is Thread
for wait(), notify(), notifyAll() it is Object


167. For what reasons might a thread stop
execution?

A. A thread with higher priority began execution.
B. The thread's wait() method was invoked.
C. The thread invoked its yield() method.
D. The thread's pause() method was invoked.
E. The thread's sleep() method was invoked.

ABCE.


168. hich method below can change a String
object, s ?

A. equals( s )
B. substring( s )
C. concat( s )
D. toUpperCase ( s )
E. none of the above will change s

E.


169. f s1 is declared as:

String sl = "phenobarbital";

hat will be the value of s2 after the following line
of code:

String s2 = s1.substring( 3, 5 );

A. null
B. "eno"
C. "enoba"
D. "no"

D.


170. hat method(s) from the java.lang.Math class
might method() be if the statement
method( -4.4 )== -4; is true.

A. round()
B. min()
C. trunc()
D. abs()
E. floor()
F. ceil()

AF.


171. hich methods does java.lang.Math include
for trigonometric computations?

A. sin( )
B. cos( )
C. tan ( )
D. aSin ( )
E. Cos ( )
F. aTan( )
G. toDegree ( )

ABC.


172. This piece of code:

TextArea ta = new TextArea ( 10, 3 );

Produces (select all correct statements):

A. a TextArea with 10 rows and up to 3 columns
B. a TextArea with a variable number of columns
not less than 10 and 3 rows
C. a TextArea that may not contain more than 30
characters
D. a TextArea that can be edited

AD.


173. n the list below, which subclass(es) of
Component cannot be directly instantiated:

A. Panel
B. Dialog
C. Container
D. Frame

C.


174. Of the five Component methods listed below,
only one is also a method of the class
Menutem. hich one?

A. setVisible (boolean b)
B. setEnabled (boolean b)
C. getSize ()
D. setForeground (Color c)
E. setBackground (Color c)

B.


175. f a font with variable width is used to construct
the string text for a column, the
initial size of the column is:

A. determined by the number of characters in the
string, multiplied by the width of a
character in this font
B. determined by the number of characters in the
string, multiplied by the average width
of a character in this font
C. exclusively determined by the number of
characters in the string
D. undetermined

B.


176. hich of the following methods from the
java.awt.Graphics class could be used to
draw the outline of a rectangle with a single method
call? Select all.

A. fillRect()
B. drawRect()
C. fillPolygon()
D. drawPolygon()
E. drawLine()

BD.


177. Of the following AT classes, which one(s)
are responsible for implementing the
components layout? Select all.

A. LayoutManager
B. GridBagLayout
C. ActionListener
D. indowAdapter
E. FlowLayout

BE.


178. A component that should resize vertically but
not horizontally should be placed in:

A. BorderLayout in the North or South location
B. FlowLayout as the first component
C. BorderLayout in the East or est location
D. BorderLayout in the Center location
E. GridLayout

C.


179. hat type of object is the parameter for all
methods of the MouseListener interface?

Answer:

MouseEvent


180. hat type of object is the parameter for all
methods of the MouseMotionListener
interface?

Answer:

MouseEvent


181. hat type of object is the parameter for all
methods of the KeyListener interface?

Answer:

KeyEvent


182. hat type of object is the parameter for all
methods of the ActionListener interface?

Answer:

ActionEvent


183. hich of the following statements about event
handling in JDK 1.1 and later are true?
Select all.

A. A class can implement multiple listener
interfaces
B. f a class implements a listener interface, it only
has to overload the methods it uses
C. All of the MouseMotionAdapter class methods
have a void return type

AC.


184. hich of the following describe the sequence
of method calls that result in a
component being redrawn?

A. invoke paint() directly
B. invoke update which calls paint()
C. invoke repaint() which
D. invoke repaint() which invokes paint() directly

C.


185. Choose all valid forms of the argument list for
the FileOutputStream constructor
shown below:

A. FileOutputStream(FileDescriptor fd)
B. FileOutputStream(String n, boolean b)
C. FileOutputStream(boolean a)
D. FileOutputStream()
E. FileOutputStream(File f)

ABE.


186. A "mode" argument such as "r" or "rw" is
required in the constructor for the
class(es):

A. DatanputStream
B. nputStream
C. RandomAccessFile
D. File
E. None of the above

C.


187. A directory can be created using a method
from the class(es):

A. File
B. DataOutput
C. Directory
D. FileDescriptor
E. FileOutputStream

A.


188. f raf is a RandomAccessFile, what is the
result of compiling and executing the
following code?

raf.seek(raf.length());

A. The code will not compile.
B. An OException will be thrown.
C. The file pointer will be positioned immediately
before the last character of the file.
D. The file pointer will be positioned immediately
after the last character of the file.

D.


189. Consider the following code: hat will be
printed?

public class ExceptionTest{

public static void main(String [] args){

ExceptionTest e = new ExceptionTest();
e.trythis();
}

public void trythis(){

try{

System.out.println("1");
problem();
}

catch (RuntimeException x){

System.out.println("2");
return;
}

catch(Exception x){
System.out.println("3");
return;
}

finally{
System.out.println("4");
}
System.out.println("5");
}


public void problem()throws Exception{

throw new Exception();
}
}

1
2
3
4
5

ACD.


190. Consider the following code: hat will be
printed?


public class ExceptionTest2{

public static void main(String[] args){

ExceptionTest2 e = new ExceptionTest2();
e.divide(4, 0);}

public void divide(int a, int b){

try{
int c = a/b;
}
catch(ArithmeticException e){

System.out.println("ArithmeticException");
}

catch(RuntimeException e){

System.out.println("RuntimeException");
}

catch(Exception e){

System.out.println("Exception");
}


finally{

System.out.println("Finally");
}
}
}

ArithmeticException
RuntimeException
Exception
Finally

A. ArithmeticException D. Finally.

191. Consider the following code: hat will be
printed?


public class ExceptionTestMindQ{

public static void main(String [] args){

ExceptionTestMindQ e = new
ExceptionTestMindQ();
e.trythis();
}

public void trythis(){

try{

System.out.println("nnan testet");
problem();
}

catch (NullPointerException x){

System.out.println("Nullpointer");

}

catch(Exception x){
System.out.println("Exception");
return;
}

finally{
System.out.println("finally");
}
System.out.println("mymethod is done");
}


public void problem()throws
llegalArgumentException{

throw new llegalArgumentException();
}
}

nnan testet
Nullpointer
Exception
finally
mymethod is done

A. nnan testet C. exception D. finally.


192. Consider the following code: hat will be
printed?

public class exceptiontest101{

public static void main(String[]args){

exceptiontest101 e = new exceptiontest101();
e.myMethod();
}
void myMethod(){
try{
fragile() ;
}
catch(NullPointerException npex){

System.out.println("NullPointerException thrown ");
}
catch(Exception ex){
System.out.println("Exception thrown ");
}
finally{
System.out.println("Done with exceptions ");
}
System.out.println("myMethod is done");
}

public void fragile() {
throw new llegalArgumentException();
}
}

NullpointerException thrown
Exception thrown
Done with exceptions
D.myMethod is done

B. Exception thrown C. Done with exceptions D.
myMethod is done


193. hat is the range of a short?

A. 128 127
B. -32 768 32 767
C. -231 231 -1
D. -263 263 -1

B.


194. hat is the range of a short?

-128 127
-231 231 1
C. -215 215 -1
D. -263 263 -1

C.


195. hat is the range of a long?

-128 127
-231 231 1
C. -215 215 -1
D. -263 263 -1

D.


196. Consider the following code: hat will be
printed?

public class Access{

int i = 10;
int j;
char z = 823;
char q = '1';
boolean b;
static int k = 9;

public static void main(String arg[]){

Access a = new Access();
a.amethod();
System.out.println(k);
}

public void amethod(){

System.out.println(j);
System.out.println(b);
System.out.println(z);
System.out.println(q);
}

}

0 true 823 1 9
null false 823 1 9
false 823 1 9 0
0 false ? 1 9
true 823 1 9 0

D.


197. Consider the following code: hat will be
printed?

public class amethod{

public static void main(String arg[]){

String s = "ello";
char c ='';
s+=c;
System.out.println(s);

}


}


A. Nothing will be printed because of a compilation
error.
B. ello
C. hello
D. ello\u345
ello

B.


198. Consider the following code: hat will be
printed?

public class Arg{
String [] MyArg;
public static void main(String arg[]){
MyArg[] = arg[];
}
public void amethod(){
System.out.println(arg[1]);
}
}
null
0
Nothing will be printed. Compilation error.
Compiles just fine, but a RuntimeException will be
thrown.

C.

199. Consider the following code: hat will be
printed?
public class Arg2{
static String [] MyArg = new String[2];
public static void main(String arg2[]){
arg2 = MyArg;
System.out.println(arg2[1]);
}

}

null
0
Nothing will be printed. Compilation error.
Compiles just fine, but a RuntimeException will be
thrown.

A.


200. Consider the following code: hat will be
printed?

public class Arraytest{
public static void main(String kyckling[]){
Arraytest a = new Arraytest();
int i[] = new int[5];
System.out.println(i[4]);
a.amethod();
Object o[] = new Object[5];
System.out.println(o[2]);

}

void amethod(){
int K[] = new int[4];
System.out.println(K[3]);
}
}

A. null null null
B. null 0 0
C. 0 0 null
D. 0 null 0

C.


201. Consider the following code: hat will be
printed?

class Arraytest2{


public static void main(String[]args){
int [] arr = {1, 2, 3};
for(int i = 0; i < 2; i++){
arr[i] = 0;
}

for(int i = 0; i < 3; i++){
System.out.println(arr [i]);
}
}
}

1 2 3
0 0 3
0 2 3
0 0 0

B.


202. Consider the following code: hat will be
printed?

public class ArrayTest3{

public static void main(String[]args){

int [][] a = new int[5][5];
System.out.println(a[4][4]);
}
}

0 0 0 0
0 0
0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

C.


203. Consider the following code: hat will be
printed?

public class booleanFlag{
public static void main(String[] args){
test();
test2();
}

public static void test(){

//boolean flag = false;

if(flag=true){

System.out.println("true");

}

else {

System.out.println("false");
}}

public static void test2(){
boolean flag = false;
if(flag==true){

System.out.println("true");
}

else {
System.out.println("false");
}
}
}

true true
true false
false true
false false
Compilation error. Cannot resolve symbol: variable
flag.

E.


204. Consider the following code: hat will be
printed?
class CeilTest{
static float k = 3.2f;
public static void main(String[]args){
System.out.println("Ceil for 3.2 is: " + Math.ceil(k) +
"Floor for 3.2 is: " + Math.floor(k));
}
}

Ceil for 3.2 is : 4.0 Floor for 3.2 is : 3.0
Ceil for 3.2 is : 3.0 Floor for 3.2 is : 4.0
Ceil for 3.2 is : 4 Floor for 3.2 is : 3
Ceil for 3.2 is : 3 Floor for 3.2 is : 4
Compiler error. Variable k cannot be reached.

A.


205. Consider the following code: hat will be
printed?

public class DoubleTest{
public static void main(String[]args){
Float i = new Float(0.9f);
Float j = new Float(0.9f);
if(i.equals(j))
System.out.println("i.equals(j)");
if(i==j)
System.out.println("i==j");
float s = 10.0f;
int t = 10;
long x = 10;
char u = 10;
if(s==t)
System.out.println("s==t");
if(x==u)
System.out.println("x==u");
}}

i.equals(j) i==j s==t x==u
B. i==j s==t x==u
C. i.equals(j) s==t x==u
i.equals(j) x==u

C. hat makes the difference here is the new
operator. You get fooled and think that s =
= t and x = = u would return false.


206. Consider the following code: hat will be
printed?

public class Equal{

public static void main(String kyckling[]){

int Output = 10;

boolean b1 = false;

if((b1==true) && ((Output+=10)==20))
{
System.out.println("e are equal " + Output);
}
else
{System.out.println("Not equal! " + Output);
}
}}

A. Nothing will be printed. You must use the word
args instead of kyckling in the main
method.
e are equal 10
Not equal 10
e are equal 20
Not equal 20

C.


207. Consider the following code: hat will be
printed?

public class EqualsTest{
public static void main(String []args){
if ("john" == "john")
System.out.println("\"john\" == \"john\"");
if("john".equals("john"));
System.out.println("\"john\".equals(\"john\")");
Boolean flag = new Boolean(true);
boolean flagga = true;
}
}

john == john
"john" == "john" "john".equals "john"
john == john john.equals john
john.equals john
"john" == "john"
"john".equals "john"

B.


208. Consider the following code: hat will be
printed?

public class EqualsTest2{

public static void main(String[]args){
byte A = (byte)4096;

if (A == 4096)
System.out.println("Equal");

else System.out.println("Not Equal");

System.out.println(A);

int B = (int)4096;

if (B == 4096)
System.out.println("Equal");

else System.out.println("Not Equal");

System.out.println(A);

}

}

Not Equal Not Equal 0
Not Equal Equal 0
Equal Not Equal 4096
Equal Equal 4096

B.

A byte can store values from 128-127. Therefore
the variable A will not be able to store
4096.


209. Consider the following code: hat will be
printed?

class Examplenteger extends Object{

public static void main(String[] args){

Examplenteger e = new Examplenteger();
e.Result(30);
}

public void ncrement(nteger N){
N = new nteger(N.intValue() + 1);
}

public void Result(int x){

nteger X = new nteger(x);
ncrement(X);
System.out.println("New value is " + X);
}
}

New value is 30
New value is 31
New value is 1
New value is null

A.


210. Consider the following code: hat will be
printed?

public class ope{
public static void main(String[]args)
{
ope h = new ope();
}
protected ope(){
for(int i = 0; i < 10; i++){

System.out.println(i);}

}}

0 1 2 3 4 5 6 7 8 9
Compiler error. Constructor cannot be protected.
1 2 3 4 5 6 7 8 9 10


211. Consider the following code: hat will be
printed?
public class nit{
public static void main(String arg[]){
int[]a = new int[5];
String s[] = new String[5];
for (int i = 0; i System.out.println(a[1]);
}
System.out.println(s[3]);
}
}

0 null 0 null 0 null 0 null 0 null
0 0 0 0 0 null null null null null
0 null
0 0 0 0 0 null
Nothing will be printed due to Compilation Error.

D.


212. Consider the following code: hat will be
printed?


public class nit2{
public static void main(String arg[]){
int[]a = new int[5];
String s[] = new String[5];
String t[];
String u;
System.out.println(a[1]);
System.out.println(s[3]);
System.out.println(t[3]);
System.out.println(u);
}

}


0 null null null
0 0 0 0 null null null null
null null null null
null 0 0 0
Nothing will be printed: Variable t and u may not
have been initialized.

E.


213. Consider the following code: hat will happen
when you try to compile it?

public class nnerClass{
public static void main(String[]args)
{}
public class Mynner{
}}

t will compile fine.
t will not compile, because you cannot have a
public inner class.
t will compile fine, but you cannot add any
methods, because then it will fail to compile.

A.


214. Consider the following code: hat will be
printed?

public class charTest2{
public static void main(String[] args){
int y = 020;
char b = '\u0010';
if(b==y)
System.out.println("Char 'u0010' = 16.0");
}
}

A. Nothing will be printed.
B. Compilation error. The char variable cannot be
assigned this way.
C. Char 'u0010' = 16.0
Compilation error. The int variable cannot be
assigned this way.
Compilation error. The char variable cannot be
assigned this way. The int variable cannot
be assigned this way.

C.


215. f you're stupid and program like this. hat will
happen?

public class LosenformationCast2{

public static void main(String[]args){

byte b = (byte)259;
short s = (short)b;

System.out.println("short s =" + s + " byte b = " + b);


}
}

short s = 3 + byte b = 3
short s = 3 byte b = 3
short s = 3 byte b = 259
Nothing will be printed. llegal explicit cast.

B.


216. f you're stupid and program like this. hat will
happen?
public class LosenformationCast{
public static void main(String[]args){
short s = 259;
byte b = (byte)s;
System.out.println("short s =" + s + "= byte b = " +
b);

}
}


short s = 259 + byte b = 3
short s = 259 = byte b = 3
short s = 3 byte b = 259
Nothing will be printed. llegal explicit cast.

B.


217. Consider the following code: hat will be
printed?
public class maze{
public static void main(String[]args){
int x = 4;
if(x<=7){
if(x==5)
System.out.println("2");
System.out.println("1");
}

else if (x==17)
System.out.println("3");

else if (x==18)
System.out.println("4");
System.out.println("0");

}

}

Nothing will be printed.
0
1 0
Compilation Error. You can not use two else if
statements in this way.
2 1 3 4 0

C.


218. Consider the following code: hat will be
printed?
public class maze2{
public static void main(String[]args){
int x= 4;
if(x<=7){
if(x==5){
System.out.println("2");
System.out.println("1");
}
}

else if (x==17)
System.out.println("3");
else if (x==18){
System.out.println("4");
System.out.println("0");
}

}

}


Nothing will be printed.
0
1 0
Compilation Error. You can not use two else if
statements in this way.
2 1 3 4 0

A.


219. Consider the following code: hat will be
printed?
public class maze3{
public static void main(String[]args){
int x= 4;
if(x<=7){
if(x==5){
System.out.println("2");
System.out.println("1");
}
}
else if (x==17)
System.out.println("3");
else if (x==18){
System.out.println("4");
}
System.out.println("0");


}

}


Nothing will be printed.
0
1 0
Compilation Error. You can not use two else if
statements in this way.
2 1 3 4 0

B.


220. Consider the following code: hat will be
printed?
public class MyAr{
public static void main(String args[]){
MyAr m = new MyAr();
m.amethod();
}
public void amethod(){
int i = 12;
System.out.println(i);
}
}

12
null
Error you cannot initialize a non-static variable in
the main method.
0

A.


221. Consider the following code: hat will be
printed?
public class MyAr{
public static void main(String args[]){
MyAr m = new MyAr();
m.amethod();
}

public void amethod(){
static int i; System.out.println(i);
}
}

A. 1
null
Syntax error: illegal start of expression. You cannot
define an integer as static inside a
non-static method
0
Syntax error: illegal start of expression. Error you
cannot define an integer as non-static
inside a static method.

C.


222. Consider the following code: hat will be
printed?
public class MyAr{
public static void main(String args[]){
MyAr m = new MyAr();
m.amethod();
}
public void amethod(){
int i;
System.out.println(i);
}
}

A. 1
null
Error. Variable i might not have been initialized.
0
Error you cannot define an integer as non-static
inside a static method.

C.


223. Consider the following code: hat will be
printed?
public class newntegerLong{
public static void main(String[]args){
nteger nA = new nteger(4096);
Long nB = new Long(4096);
if(nA.equals(nB))
System.out.println("LongEqualsnteger.");
if(nA.intValue() == nB.longValue()){
System.out.println("f you create new primitive
values of Long(4096) and nteger(4096),
then == true.");

}}}

LongEqualsnteger.
f you create new primitive values of Long(4096)
and nteger(4096), then == true.
LongEqualsnteger. f you create new primitive
values of Long(4096) and nteger(4096),
then == true.
f you create new primitive values of Long(4096)
and nteger(4096), then == true.
Nothing will be printed.

B.


224. Consider the following code: hat will be
printed?

public class Q{
public static void main(String arg[]){
int anar[] = new int[]{1,2,3};
System.out.println(anar[1]);
int i = 9;
switch(i){
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
boolean b=true;
boolean b2 = true;
if (b==b2){
System.out.println("So true");
}
}
}


2 default so true
2 default zero so true
1 default zero so true
0 default so true
2 default zero two
2 default zero two so true

B.


225. Consider the following code: hat will be
printed?
public class Scope{
private int i;
public static void main(String arg[]){
Scope s = new Scope();
s.amethod();
}

public static void amethod(){
System.out.println(i);
}

}

0
null
Error. Non-static variable i cannot be referenced
from a static context.
Error. Variable may not have been initialized.

C.


Consider the following code: hat will be printed?
public class StringBuf{
public static void main(String args[]){
StringBuffer sb = new StringBuffer("abc ");
String s = new String(" a b c");
String st = "ABCDE";
sb.append("def ");//nu r s = abc def
sb.insert(1, " zzz ");//nu r s = a zzz bc def
String i = s.concat(st);
s = s.trim();
System.out.println(s);
System.out.println(sb);
System.out.println(st.indexOf("C"));
System.out.println(st.indexOf('A'));
System.out.println(st.indexOf('A', 2));
System.out.println(st.indexOf('G'));
System.out.println(i);
}
}

hat will be printed?


abc
azzz bc def
2
0
-1
-1
a b cABCDE


a b c
abc def zzz
2
0
-1
-1
a b c ABCDE

C.
abc
abcdefzzz
2
0
1
-1
a b c ABCDE

D.
a b c
a zzz bc def
2
0
-1
-1
a b cABCDE

D.

227. Consider the following code: hat will be
printed?

public class StringBufferTest{

public static void main(String[]args){

StringBuffer sb1 = new StringBuffer("Anna");
StringBuffer sb2 = new StringBuffer("Anna");

if (sb1.equals(sb2))

System.out.println("Equals");

else

System.out.println("StringBuffer Equals not");

String s1 = new String("Anna");
String s2 = new String("Anna");

if (s1.equals(s2))

System.out.println("String Equals");

else

System.out.println("Equals not");
}
}


Equals
Equals not

StringBuffer Equals not
String Equals

Equals
String Equals
D.
StringBuffer Equals not
Equals not

B.

228. Consider the following code: hat will be
printed?

public class StringBufferTest2{
public static void main(String[]args){
String a, b;
StringBuffer c, d;
c = new StringBuffer("Kalle");
a = new String("Kalle");
b = a;
d = c;
StringBuffer e = new StringBuffer("Kalle");
String f = new String("Kalle");
if(b.equals(a))
System.out.println("b.equals(a)");
if(b==a)
System.out.println("b==a");
if(d.equals(c))
System.out.println("d.equals(c)");
if(d==c)
System.out.println("d==c");
if(f.equals(a))
System.out.println("f.equals(a)");
if(f==a)
System.out.println("f==a");
else
System.out.println("f!=a");
if(e.equals(c))
System.out.println("e.equals(c)");
else
System.out.println("e.equalsnot(c)");
if(e==c)
System.out.println("e==c");
else
System.out.println("e!=c");
}
}

A.
b.equals(a)
b==a
d.equals(c)
d==c
f.equals(a)
f!=a
e.equalsnot(c)
e!=c

B.
b.equals(a)
b==a
d.equals(c)
d==c
f!=a
e.equalsnot(c)
e!=c

C.
b.equals(a)
d.equals(c)
f.equals(a)
f==a
e.equals(c)
e!=c

D.
b==a
d==c
f.equals(a)
f!=a
e.equalsnot(c)
e==c

E.
b.equals(a)
b==a
d.equals(c)
d==c
f.equals(a)
e.equals(c)
e!=c

A.

229. Consider the following code: hat will be
printed?
public class StringTest{
public static void main(String[] args){
String s = "Kalle och Matte";
int i = s.length();
int j = args.length;
System.out.println(i + " " + j);
}}

13 13
13 0
15 0
15 13
15 null
15 + + 0
13 + + 0

C.

230. Check and run this code and you will see how
the round method in the
Java.lang.math class will behave when you have
4.5 and 4.5. t will round up. You will
also see how substring(); floor(); and ceil(); behave.
import java.lang.Math;
public class Substr{
public static void main(String[]args){
String s1 = ("Kalle Bengtsson");
String s2 = s1.substring(0,5);
System.out.println(s2);
s1 = ("phenobarbital");
s2 = s1.substring(3,5);
System.out.println(s2);

long i = Math.round(-4.4);
System.out.println("Math.round(-4.4) = " + i);

long j = Math.round(4.5);
System.out.println("Math.round(4.5) = " + j);

long k = Math.round(-4.5);
System.out.println("Math.round(-4.5) = " + k);

int l = (int)(Math.ceil(-4.4));
System.out.println("Math.ceil(-4.4) = " + l);

int m = (int)Math.ceil(-4.5);
System.out.println("Math.ceil(-4.5) = " + m);

int n = (int)Math.ceil(4.4);
System.out.println("Math.ceil(4.4) = " + n);

int o = (int)Math.floor(-4.4);
System.out.println("Math.floor(-4.4) = " + o);

int p = (int)Math.floor(4.4);
System.out.println("Math.floor(4.4) = " + p);

int q = (int)Math.floor(4.5);
System.out.println("Math.floor(4.5) = " + q);
}
}


231. Consider the following code: hat will be
printed?
public class Testa
{
nteger a = 10;
nteger b = 20;
nteger c = 10;
public static void main (String[] args){
if (a==c){
System.out.println("Fel");
}

if (a.equals(c)){
System.out.println("rtt");
}
}
}

Fel rtt
rtt
Fel
None will be printed. A NullPointerException will be
thrown.
None will be printed. Compilation error.
ncompatible types and a non-static variable
cannot be referenced from a static context.


Consider the following code: hat will be printed?

public class Testb
{
static nteger a = 10;
static nteger b = 20;
static nteger c = 10;
public static void main (String[] args){

if (a==c){
System.out.println("Fel");
}

if (a.equals(c)){
System.out.println("rtt");
}

}
}

Fel rtt
rtt
Fel
None will be printed. A NullPointerException will be
thrown.
None will be printed. Compilation error.
ncompatible types and a non-static variable
cannot be referenced from a static context.
None will be printed. Compilation error.
ncompatible types.

F.


232. Consider the following code: hat will be
printed?

public class Testc
{

static nteger a = new nteger(10);
static nteger b;
static nteger c = new nteger(10);

public static void main (String[] args){

if (a==c){
System.out.println("Fel");
}

if (a.equals(c)){
System.out.println("rtt");
}

}
}

Fel rtt
rtt
Fel
None will be printed. A NullPointerException will be
thrown.
None will be printed. Compilation error.
ncompatible types and a non-static variable
cannot be referenced from a static context.
None will be printed. Compilation error.
ncompatible types.

B.


233. Consider the following code: hat will be
printed?

class Unchecked{
public static void main(String[]args){
try{
method();
}
catch (Exception e) {
System.out.println("Fngar Exception");
}
}
static void method(){
try{
method1();
System.out.println("Testar method1");
}

catch (ArithmeticException ae) {
System.out.println("Fngar ArithmeticException");
}
finally{
System.out.println("Kr finally");
}
System.out.println(" method() utanfr finally");
}

static void wrench(){
throw new NullPointerException();
}
}

A. Kr finally. method() utanfr finally. Fngar
Exception.
Kr finally. Fngar Exception.
None.
Kr finally.

B.


234. Consider the following code: hat will be
printed?

class Unchecked1{
public static void main(String[]args){
}
void method(){
try{
metod1();
System.out.println("Testar metod1");
}
catch (ArithmeticException ae) {
System.out.println("Fngar ArithmeticException");
}
finally{
System.out.println("Kr finally");
}
System.out.println(" method() utanfr finally");
}

void metod1(){
throw new NullPointerException();
}
}


Kr finally. method() utanfr finally. Fngar
Exception.
Kr finally. Fngar Exception.
None.
Kr finally.

C. (Strange but thats it).



Originally created by Thomas Leuthard.

Updated by Sasa.

Kept alive by you.


1. hich statement are characteristics of the >> and >>> operators.

A. >> performs a shift
B. >> performs a rotate
C. >> performs a signed and >>> performs an
unsigned shift
D. >> performs an unsigned and >>> performs a
signed shift
E. >> should be used on integrals and >>> should
be used on floating point types

C.


2. Given the following declaration

String s = "Example";

hich are legal code?

A. s >>> = 3;
B. s[3] = "x";
C. int i = s.length();
D. String t = "For " + s;
E. s = s + 10;

CDE.


3. Given the following declaration

String s = "hello";

hich are legal code?

A. s >> = 2;
B. char c = s[3];
C. s += "there";
D. int i = s.length();
E. s = s + 3;

CDE.


4. hich statements are true about listeners?

A. The return value from a listener is of boolean
type.
B. Most components allow multiple listeners to be
added.
C. A copy of the original event is passed into a
listener method.
D. f multiple listeners are added to a single
component, they all must all be friends to
each other.
E. f the multiple listeners are added to a single
component, the order [in which listeners
are called is guaranteed].

BC.


5. hat might cause the current thread to stop
executing.

A. An nterruptedException is thrown.
B. The thread executes a wait() call.
C. The thread constructs a new Thread.
D. A thread of higher priority becomes ready.
E. The thread executes a waitforD() call on a
MediaTracker.

ABDE.


6. Given the following incomplete method.

1. public void method(){
2.
3. if (someTestFails()){
4.
5. }
6.
7.}

You want to make this method throw an
OException if, and only if, the method
someTestFails() returns a value of true.
hich changes achieve this?

A. Add at line 2: OException e;
B. Add at line 4: throw e;
C. Add at line 4: throw new OException();
D. Add at line 6: throw new OException();
E. Modify the method declaration to indicate that an
object of [type]
Exception might be thrown.

DE. (E suppose they mean the method declaration
for someTestFails.)


7. hich modifier should be applied to a method for
the lock of the object this to be
obtained prior to executing any of the method
body?

A. final
B. static
C. abstract
D. protected
E. synchronized

E.


8. hich are keywords in Java?

A. NULL
B. true
C. sizeof
D. implements
E. instanceof

DE.


9. Consider the following code:

nteger s = new nteger(9);
nteger t = new nteger(9);
Long u = new Long(9);

hich test would return true?

A. (s==u)
B. (s==t)
C. (s.equals(t))
D. (s.equals(9))
E. (s.equals(new nteger(9))

CE.


10. hy would a responsible Java programmer
want to use a nested class?

Don't know the answers. But here are some
reasons from Exam Cram.

To keep the code for a very specialized class in
close association with the class it works
with.
To support a new user interface that generates
custom events.
To impress the boss with his/her knowledge of Java
by using nested classes all over the
place.

AB.


11. You have the following code. hich numbers
will cause "Test2" to be printed?

switch(x){

case 1:
System.out.println("Test1");
case 2:

case 3:
System.out.println("Test2");
break;
}
System.out.println("Test3");
}

A. 0
B. 1
C. 2
D. 3
E. 4

BCD.




12. hich statement declares a variable a which is
suitable for referring to an array of 50
string objects?

A. char a[][];
B. String a[];
C. String []a;
D. Object a[50];
E. String a[50);
F. Object a[];

BCF.


13. hat should you use to position a Button within
an application frame so that the
width of the Button is affected by the Frame size
but the height is not affected.

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

E.


14. hat might cause the current thread to stop
executing?

A. An nterruptedException is thrown
B. The thread executes a sleep() call
C. The thread constructs a new Thread
D. A thread of higher priority becomes ready
(runnable)
E. The thread executes a read() call on an
nputStream

ABDE.


Non-runnable states:

* Suspended: caused by suspend(), waits for
resume()
* Sleeping: caused by sleep(), waits for timeout
* Blocked: caused by various /O calls or by failing
to get a monitor's lock, waits for /O or
for the monitor's lock
* aiting: caused by wait(), waits for notify() or
notifyAll()
* Dead: Caused by stop() or returning from run(), no
way out

From Certification Study Guide p. 227


15. Consider the following code:

String s = null;

hich code fragments cause an object of type
NullPointerException to be thrown?

A. if((s!=null) & (s.length()>0))
B. if((s!=null) &&(s.length()>0))
C. if((s==null) | (s.length()==0))
D. if((s==null) || (s.length()==0))

AC.


16. Consider the following code:

String s = null;

hich code fragments cause an object of type
NullPointerException to be thrown?

A. if((s==null) & (s.length()>0))
B. if((s==null) &&(s.length()>0))
C. if((s!=null) | (s.length()==0))
D. if((s!=null) || (s.length()==0))

ABCD.


17. hich statement is true about an inner class?

A. t must be anonymous
B. t can not implement an interface
C. t is only accessible in the enclosing class
D. t can only be instantiated in the enclosing class
E. t can access any final variables in any enclosing
scope.

E.


18. hich statements are true about threads?

A. Threads created from the same class all finish
together
B. A thread can be created only by subclassing
Java.Lang.Thread.
C. nvoking the suspend() stops a thread so that it
cannot be restarted
D. The Java nterpreter's natural exit occurs when
no non daemon threads remain alive
E. Uncoordinated changes to shared data by
multiple threads may result in the data being
read, or left, in an inconsistent state.

DE.


19. Consider the following code:

1. public void method(String s){
2. String a,b;
3. a = new String("ello");
4. b = new String("Goodbye");
5. System.out.println(a + b);
6. a = null;
7. a = b;
8. System.out.println(a + b);
9. }

here is it possible that the garbage collector will
run the first time?

A. Just before line 5
B. Just before line 6
C. Just before line 7
D. Just before line 8
E. Never in this method

C.


20. hich code fragments would correctly identify
the number of arguments passed via
the command line to a Java application, excluding
the name of the class that is being
invoked?

A. int count = args.length;
B. int count = args.length - 1;
C. int count = 0;
while (args[count] != null)
count ++;
D. int count = 0;
while (!(args[count].equals("")))
count ++;

A.


21. hich are keywords in Java?

A. sizeof
B. abstract
C. native
D. NULL
E. BOOLEAN

BC.


22. hich are correct class declarations? Assume
in each case text constitutes the entire
contents of a file called Fred.java on a system with
a case-significant system.

A. public class Fred {
public int x = 0;
public Fred (int x) {
this.x = x;
}
}

B. public class fred {
public int x = 0;
public fred (int x) {
this.x = x;
}
}

C. public class Fred extends MyBaseClass,
MyOtherBaseClass {
public int x = 0;
public Fred (int xval) {
x = xval;
}
}

D. protected class Fred {
private int x = 0;
private Fred (int xval) {
x = xval;
}
}

E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}

AE.


B is wrong because of case-sensitivity. C is wrong
because multiple inheritance is not
supported in Java. D is wrong because a class can
only be public, abstract, final or default
(with no access modifier).


23. hich are correct class declarations? Assume
in each case text constitutes the entire
contents of a file called Test.java on a system with
a case-significant system.

A. public class Test {
public int x = 0;
public Test (int x) {
this.x = x;
}
}

B. public class Test extends MyClass,
MyOtherClass {
public int x = 0;
public Test (int xval) {
x = xval;
}
}

C. import java.awt.*;
public class Test extends Object {
int x;
private Test (int xval) {
x = xval;
}
}


D. protected class Test {
private int x = 0;
private Test (int xval) {
x = xval;
}
}

AC.


24. A class design requires that a particular
member variable must be accesible for direct
access by any subclasses of this class, otherwise
not by classes which are not members
of the same package. hat should be done to
achieve this?

A. The variable should be marked public
B. The variable should be marked private
C. The variable should be marked protected
D. The variable should have no special access
modifier
E. The variable should be marked private and an
accessor method provided

C.


25. hich correctly create an array of five empty
Strings?

A. String a [] = new String [5];
for (int i = 0; i < 5; a[i++] = "");

B. String a [] = {"", "", "", "", "", ""};

C. String a [5];
D. String [5] a;
E. String [] a = new String[5];
for (int i = 0; i < 5; a[i++] = null);

AB.


26. hich cannot be added to a Container?

A. an Applet
B. a Component
C. a Container
D. a Menu
E. a Panel

D.


27. FilterOutputStream is the parent class for
BufferedOutputStream, DataOutputStream
and PrintStream. hich classes are a valid
argument for the constructor of a
FilterOutputStream?

A. nputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer

B.


28. FilternputStream is the parent class for
BufferednputStream and DatanputStream.
hich classes are a valid argument for the
constructor of a FilternputStream?

A. File
B. nputStream
C. OutputStream
D. FilenputStream
E. RandomAccessFile

B.


29. Given the following method body:

{
if (atest()) {
unsafe():
}
else {
safe();
}
}

The method "unsafe" might throw an
ATException (which is not a subclass of
RunTimeException). hich correctly completes the
method of declaration when added at
line one?

A. public ATException methodName()
B. public void methodname()
C. public void methodName() throw ATException
D. public void methodName() throws
ATException
E. public void methodName() throws Exception

DE.


30. Given a TextArea using a proportional pitch font
and constructed like this:

TextField t = new TextArea("12345", 5, 5);

hich statement is true?

A. The displayed width shows exactly five
characters on each line unless otherwise
constrained.
B. The displayed height is five lines unless
otherwise constrained.
C. The maximum number of characters in a line will
be five.
D. The user will be able to edit the character string.
E. The displayed string can use multiple fonts.

BD.


31. Given this skeleton of a class currently under
construction:

public class Example {
int x, y;

public Example(int a){
//lots of complex computation
x = a;
}

public Example(int a, int b) {
/*do everything the same as single argument
version of constructor
including assignment x = a */
y = b;
}
}

hat is the most concise way to code the "do
everything..." part of the constructor
taking two arguments?

Answer:

this(a);


32. Given this skeleton of a class currently under
construction:

public class Example {
int x, y;

public Example(int a, int b){
//lots of complex computation
x = a;
}

public Example(int a, int b, long c) {
/*do everything the same as the two argument
version of constructor
including assignment x = a */
y = b;
}
}

hat is the most concise way to code the "do
everything..." part of the constructor
taking two arguments?

Answer:

this(a, b);

arning! A similar question will appear with at least
two classes, then it is
super("arguments"); that you should use.


33. hich correctly create a two dimensional array
of integers?

A. int a [][] = new int [10,10];
B. int a [10][10] = new int [][];
C. int a [][] = new int [10][10];
D. int []a[] = new int [10][10];
E. int [][]a = new int [10][10];

CDE.


34. Given the following method body:

{
if (sometest()) {
unsafe();
}
else {
safe();
}
}

The method "unsafe" might throw an OException
(which is not a subclass of
RunTimeException). hich correctly completes the
method of declaration when added at
line one?

A. public void methodName() throws Exception
B. public void methodname()
C. public void methodName() throw OException
D. public void methodName() throws OException
E. public OException methodName()

AD.


35. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {
static int x;

public static void main(String args[]){
System.out.println("Value is " + x);
}
}

A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

A.


36. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {
public int x;

public static void main(String args[]){
System.out.println("Value is " + x);
}
}

A. The output "Value is 0" is printed.
B. Non-static variable x cannot be referenced from
a static context..
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

B.


37. hat would be the result of attempting to
compile and run the following piece of
code?

public class Test {


public static void main(String args[]){
int x;
System.out.println("Value is " + x);
}
}

A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler
error occurs.
D. A "possible reference before assignment"
compiler error occurs.
E. An object of type
ArrayndexOutOfBoundsException is thrown.

D. Compiler says variable x might not have been
initialized.


38. hat should you use to position a Button within
an application Frame so that the size
of the Button is NOT affected by the Frame size?

A. a FlowLayout
B. a GridLayout
C. the center area of a BorderLayout
D. the East or est area of a BorderLayout
E. The North or South area of a BorderLayout

A.


For the following six questions you will be
presented with a picture in the real test,
showing the relationship and quite long text, but
don't be afraid the questions are quite
easy.


39. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
p = d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

C.


40. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d2 = d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

A.


41. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)d2;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

A. llegal both at compile and runtime. You cannot
assign an object to a sibling reference,
even with casting.


43. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)p;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

B.


44. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = p;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

A.


45. e have the following organization of classes.

class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}

hich of the following statements is correct for the
following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
p = (Parent)d1;

A. llegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
D. ....
E. ....

C.


46. hat would you use when you have duplicated
values that needs to be sorted?

A. Map
B. Set
C. Collection
D. List
E. Enumeration

D.


47. hat kind of reader do you use to handle ASC
code?

A. BufferedReader
B. ByteArrayReader
C. Printriter
D. nputStreamReader
E. ?????

D.


nputStreamReader and FileReader automatically
converts from a particular character
encoding to Unicode. From Core Java Advanced
Features p. 820.


48. ow can you implement encapsulation in a
class?

A. Make all variables protected and only allow
access via methods.
B. Make all variables private and only allow access
via methods.
C. Ensure all variables are represented by wrapper
classes.
D. Ensure all variables are accessed through
methods in an ancestor class.

B.


49. hat is the return-type of the methods that
implement the MouseListener interface?

A. boolean
B. Boolean
C. void
D. Pont

C.


50. hat is true about threads that stop executing?

A. hen a running thread's suspend() method is
called, then it is indefinitely possible for
the thread to start.
B. The interpreter stops when the main method
stops.
C. A thread can stop executing when another
thread is in a runnable state.
D. ......
E. ......

C.


51. For which of the following code will produce
"test" as output on the screen?

A. int x=10.0;
if (x=10.0)
{
System.out.println("test");
}

B. int x=012;
if (x=10.0)
{
System.out.println("test");
}

C. int x=10f;
if (x=10.0)
{
System.out.println("test");
}

D. int x=10L;
if (x=10.0)
{
System.out.println("test");
}

B.


52. Given this class ?

class Loop {
public static void main (String [] args){
int x=0;
int y=0,
outer: for (x=0; x<100;x++) {
middle: for (y=0;y<100y++) {

System.out.printl("x=" + x + "; y=" + y);

if (y==10){

<<<>>>}
}
}
}//main
}//class

The question is which code must replace the
<<<>>> to finish the outer loop?
A. continue middle;
B. break outer;
C. break middle;
D. continue outer;
E. none of these...

B.


53. hat does it mean when the handleEvent()
returns the true boolean?

A. The event will be handled by the component.
B. The action() method will handle the event.
C. The event will be handled by the
super.handleEvent().
D. Do nothing.

A.


54. hat is the target in an Event?

A. The Object() where the event came from.
B. The Object() where the event is destined for.
C. hat the Object() that generated the event was
doing.

A.


55. hat is the statement to assign a unicode
constant CODE with 0x30a0?

Answer:

public static final char CODE='\u30a0';



56. The following code resides in the source?

class StringTest {

public static void main (String [] args){
//
// String comparing
//
String a,b;
StringBuffer c,d;
c = new StringBuffer ("ello");
a = new String("ello");
b = a;
d = c;

if (<<>>) {}
}
}//class

hich of the following statement return true for the
<<>> line in StringTest.class?

A. b.equals(a)
B. b==a
C. d==c
D. d.equals(c)

ABCD.


57. hich are valid identifiers?

A. %fred
B. *fred
C. thisfred
D. 2fred
E. fred

CE.


58. e have the following class X.

public class X {

public void method();

}

<<>>

hich of the following statement return true for the
<<>> line in StringTest.class?

A. abstract void method() ;
B. class Y extends X {}
C. package java.util;
D. abstract class z { }

BD.


59. hich code fragments would correctly identify
the number of arguments passed via
the command line to a Java Application?

A. int count = args.length;
B. int count = 0;
while args[count] !=null)
count++;
C. int count = 0;
while (!(args[count].equals("")))
count++;
D. int count = args.length - 1;

A.


60. Given a TextField that is constructed like this:

TextField t = new TextField(30);

hich statement is true?

A. The displayed width is 30 columns.
B. The displayed string can use multiple fonts.
C. The user will be able to edit the character string.
D. The displayed line will show exactly thirty
characters.
E. The maximum number of characters in a line will
be thirty.

AC.


61. hat does the java runtime option -cs do?

A. check source with debug report
B. clear classes that are existing when starting
compilation.
C. check if the source is newer when loading
classes.

C.


62. hen is an action invoked?

A. TextField Enter
B. TextArea Enter
C. Scrollbar
D. MouseDown
E. Button

AE.


63. hat error does the following code generate?

class SuperClass{

SuperClass(String s){}
}

class SubClass extends SuperClass{
SubClass(){}
}

......

SubClass s1 = new SubClass("The");
SuperClass s = new SubClass("The");

A. java.lang.ClassCastException
B. rong number of arguments in constructor
C. ncompatible type for =. Can't convert SubClass
to SuperClass.
D. No constructor matching SuperClass found in
class SuperClass.

BD.


64. ow do you declare a native method called
myMethod in Java?

Answer:

public native void myMethod();


65. hat should you use to position a component
within an application frame so that the
components height is affected by the Framesize?

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

D.


66. hat should you use to position a component
within an application frame so that the
components width is affected by the Framesize?

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

E.


67. hat should you use to position a Button within
an application frame so that the
height of the Button is affected by the Frame size
but the width is not affected.

A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or est of a BorderLayout
E. North or South of a BorderLayout

D.


68. hich are keywords in Java?

A. NULL
B. sizeof
C. friend
D. extends
E. synchronized

DE.


69. hich is the advantage of encapsulation?

A. Only public methods are needed.
B. No exceptions need to be thrown from any
method.
C. Making the class final causes no consequential
changes to other code.
D. t changes the implementation without changing
the interface and causes no
consequential changes to other code.
E. t changes the interface without changing the
implementation and causes no
consequential changes to other code.

D.


70. hat can contain objects that have a unique
key field of String type, if it is required
to retrieve the objects using that key field as an
index?

A. Map
B. Set
C. List
D. Collection
E. Enumeration

A.


71. hich statement is true about a non-static inner
class?

A. t must implement an interface.
B. t is accessible from any other class.
C. t can only be instantiated in the enclosing class.
D. t must be final if it is declared in a method
scope.
E. t can access private instance variables in the
enclosing object.

E.


72. hich declares an abstract method in an
abstract Java class?

A. public abstract method();
B. public abstract void method();
C. public void abstract Method(};
D. public void method() {abstract;/}
E. public abstract void method() {/}

B.

73. hich statements on the<<< call>>> line are
valid expressions?

public class SuperClass {
public int x;
int y;
public void m(int a) {}
Superclass(){ }
}
class SubClass extends SuperClass{
private float f;
void m2() { return; }
SubClass() { }
}
class T {
public static void main (String [] args) {
int i;
float g;
SubClass b = SubClass();
<<< calls >>>
}
}

A. b.m2();
B. g=b.f;
C. i=b.x;
D. i=b.y;
E. b.m(6);

ACDE.


74. Type 7 in hexadecimal form.

Answer:

0x7


75. Type 7 in octal form.

Answer:

07


76. hat is the range of an integer?

A. -128127
B. -32 768 32 767
C. -231 231 -1
D. -232 232 -1

C.


77. hat is the range of a char?

A. \u0000 \uFFFF
B. -32 768 32 767
C. -128 127
D. -231 231 -1

A.


78. hat is the range of a char?

A. 0 215-1
B. -32 768 32 767
C. - 2 16 216-1
D. 0 216-1

D.


79. hich method contains the code-body of a
thread?

A. start()
B. run()
C. init()
D. suspend()
E. continue()

B.


80. hat can you place first in this file?

//hat can you put here?

public class Apa{}

A. class a implements Apa
B. protected class B {}
C. private abstract class{}
D. import java.awt.*;
E. package dum.util;
F. private int super = 1000;

ADE.


81. hat is the output of the following code?

outer: for(int i=1; i<3; i++){
inner: for(int j=1; j<3; j++){
if (j==2){
continue outer;
}
System.out.println(i+" and "+j);
}
}

A. 1 and 1
B. 1 and 2
C. 2 and 1
D. 2 and 2
E. 2 and 3
F. 3 and 2
G. 3 and 3

AC.


82. hat is the output of the following code?

outer: for(int i=1; i<2; i++){
inner: for(int j=1; j<2; j++){
if (j==2){
continue outer;
}
System.out.println(i " and " j);
}
}

A. 1 and 1
B. 1 and 2
C. 2 and 1
D. 2 and 2
E. 2 and 3
F. 3 and 2
G. 3 and 3

A.


83. ow do you declare a native method?

A. public native method();
B. public native void method();
C. public void native method();
D. public void native() {}
E. public native void method() {}

B.


84. Given the following code, what is the output
when a exception other than a
NullPointerException is thrown?

try{

//some code
}
catch(NullPointerException e) {
System.out.println("thrown 1");
}
finally {
System.out.println("thrown 2");
}
System.out.println("thrown 3");


A thrown 1
B thrown 2
C thrown 3
D none

BC.


85. You have been given a design document for a
employee system for implementation in
Java. t states.
bla bla bla

choose between the following words:

public
class
object
extends
Employee
Person
plus at least five more

ow should you name the class?

Answer:

public class Employee extends Person


86. You have been given a design document for a
polygon system for implementation in
Java. t states.

A polygon is drawable, is a shape. You must
access it. t should have values in a vector
bla bla

hich variables should you use?

choose between the following words:

public
object
vector
drawable
color
plus some more

Answer:

vector, color (not sure)


87. You have been given a design document for a
polygon system for implementation in
Java. t states. A polygon is a Shape. You must
access it. t has a vector and corners bla
bla

choose between the following words: hat will you
write when defining the class?

public
class
Polygon
object
extends
Shape
plus some more

Answer:

public class Polygon extends Shape


88. hat is true about the garbage collection?

A. The garbage collector is very unpredictable.
B. The garbage collector is predictable.
C.
D.
E.

A.


87. hat is true about a thread?

A The only way you can create a thread is to
subclass java.lang.Thread
B f a Thread with higher priority than the currently
running thread is created, the thread
with the higher priority runs.
C.
D.
E.

B (not sure)


88. hat happens when you compile the following
code?

public classTest {

public static void main(String args[] ) {
int x;
System.out.println(x);
}

A. Error at compile time. Malformed main method
B. Clean compile
C. Compiles but error at runtime. X is not initialized
D.
E. Compile error. Variable x may not have been
initialized.

E.


89.hat happens hen you run the following
program with the command:

java Prog cat dog mouse

public class Prog {

public static void main(String args[]) {
System.out.println(args[0]) ;
}

A. Error at compile time.
ArrayndexOutOfBoundsException thrown
B. Compile with no output
C. Compile and output of dog
D. Compile and output of cat
E. Compile and output of mouse

D.


90. hich number for the argument must you use
for the code to print cat?

ith the command:

java Prog dog cat mouse

public class Prog {

public static void main(String args[]) {
System.out.println(args[?]) ;
}
}

A. 0
B. 1
C. 2
D. 3
E. none of these

B.


91. hich number for the argument must you use
for the code to print cat?
ith the command:

java Prog cat dog mouse

public class Prog {

public static void main(String args[]) {
System.out.println(args[?]) ;
}
}

A. 0
B. 1
C. 2
D. 3
E. none of these

A.


92. You have the following code:

.......
String s;
s = "ello";
t = " " + "my";
s.append(t);
s.toLowerCase();
s+= " friend";
System.out.println(s);

hat will be printed?

Answer:

hello my friend


93. hat will happen when you attempt to compile
and run this code?

public class MySwitch{

public static void main(String argv[]) {
MySwitch ms = new MySwitch();
ms.amethod();
}

public void amethod() {

char k=10;

switch(k){
default:
System.out.println("This is the default output");

break;
case 10:
System.out.println("ten");
break;
case 20:
System.out.println("twenty");
break;
}
}
}

A. None of these options
B. Compile time error target of switch must be an
integral type
C. Compile and run with output "This is the default
output"
D. Compile and run with output "ten"

D.


94. hat will happen when you attempt to compile
and run the following code?

public class MySwitch{

public static void main(String argv[]) {
MySwitch ms = new MySwitch();
ms.amethod();
}

public void amethod() {

int k=10;
switch (k){
default: //Put the default at the bottom, not here
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
case 20:
System.out.println("twenty");
break;
}
}
}

A. None of these options
B. Compile time error target of switch must be an
integral type
C. Compile and run with output "This is the default
output
D. Compile and run with output "ten"

A.


95. hich of the following statements are true?
A. For a given component, events will be processed
in the order that the listeners were
added
B. Using the Adapter approach to event handling
means creating blank method bodies for
all event methods
C. A component may have multiple listeners
associated with it
D. Listeners may be removed once added

CD.


Button for instance has the methods
addActionListener (ActionListener a) and
removeActionListener(ActionListener a).


96. hich of the following statements are true?
A. Directly subclassing Thread gives you access to
more functionality of the Java
threading capability than using the Runnable
interface
B. Using the Runnable interface means you do not
have to create an instance of the
Thread class and can call run directly
C. Both using the Runnable interface and
subclassing of Thread require calling start to
begin execution of a Thread
D. The Runnable interface requires only one
method to be implemented, this method is
called run

CD.


97. f you want subclasses to access, but not to
override a superclass member method,
what keyword should precede the name of the
superclass method?

Answer:

final


98. f you want a member variable to not be
accessible outside the current class at all,
what keyword should precede the name of the
variable when declaring it?

Answer:

private
99. hich of the following are correct methods for
initializing the array "dayhigh" with 7
values?
A. int dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
B. int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };
C. int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
D. int dayhigh [] = new int [24, 23, 24, 25, 25, 23,
21];
E. int dayhigh = new [24, 23, 24, 25, 25, 23, 21] ;

BC.
100. Assume that val bas been defined as an int for
the code below.

if(val > 4){
System.out.println("Test A");
}
else if(val > 9){
System.out.println("Test B");
}
else System.out.println("Test C");
hich values of val will result in "Test C" being
printed:
A. val < 0
B val between 0 and 4
C val between 4 and 9
D val > 9
E val = 0
F no values for val will be satisfactory

ABE.
Q-1 int b1 = << 31;
int b2 = << 31;
b1 >>> = 31;
b1 >>> =1;
b2 >> = 31;
b2 >> = 1;

Ans: (a) b1 all zeros & b2 all zeros
(b) b1 all zeros & b2 all ones
(c) b1 all ones & b2 all zeros
(d) b1 all ones & b2 all ones

Q-2 hich of following expressions throws "Null Pointer Exception" given String
S=null;

Ans: (a) if (S1 = null & s.length ( ) > o)
(b) if (S1 = null & s.length ( ) > o)
(c) if (S == null / s.length ( ) ==o)
(d) if (S == null ll s.length ( ) ==o)

Q-3 ow can you define an array of 10 by 10 with all zeros ?
(a) int a[][]=new [10,10]
(b) int a[10][10] = new int[][]
(c) int a[][]=new int[10][10]
(d) int []a[]=new int[10][10]
(e) int a[][]=new int[][]

Q-4 hich of the following operations can be done on String
String s = "abcdef";
(a)s>>>=4;
(b)s[3]=a;
(c)s=s.trim();
(d)s=s.toUppercase();
(e)s.equals("xyz");
(f)s.append("xyz");
(g)s.subString(3);

Q-5 Following can be placed at Point1

// Point1
public class Xyz{
}

(a) import java.awt.*;
(b) public class Abc{ }
(c) package my.util.*;
(d) import lang.util.*;
(e) protected class pqr{ }

Q-6 n order to read a file line by line which is most preffered way
(a) FilenputStream fis = new FilenputStream("a.dat");
(b) DatanputStream dis = new DatanputStream(new
FilenputStream("a.dat",r));
(c) DatanputStream dis = new DatanputStream(new
FilenputStream("a.dat"));
(d) BufferedReader br = new BufferedReader(new FileReader("file");

Q-7 ntially "old.dat" file consists of 10 bytes of data after the following operation
what is the length of the file "old.dat" ?

FileOutputStream fos = new FileOutputStream("old.dat");
DataOutputStream dos = new DataOutputStream(fos);
dos.write(bye);

(a) 8
(b) 14
(c) 4
(d) 20
(e) none

Q-8 hich is the valid argument passed to constructor of FilternputStream
(a) FilenputStream
(b) BufferednputStream
(c) File
(d) RandomAccessFile
(e) DatanputStream

Q-9 Following cannot be added to a Container
(a)Component
(b)Panel
(c)Menutem
(d)Container

Q-10 f following method may throw OException ow do you declare the method
in a proper way

(a) public void OException{ }
(b) void method throw OException{ }
(c) public void method throws OException{ }

Q-11 hat will be the output for the following code
Outer: for(int i=1;i<3;i++) {
for(int j=1;j<3;j++){
if(j==2){ continue Outer; }
System.out.println(" i : "+i+" j : "+j);
}
}
(a) i=0 j=0
(b) i=1 j=0
(c) i=0 j=1
(d) i=1 j=1
(e) i=2 j=1
(f) i=1 j=2
(g) i=2 j=0
(h) i=0 j=2
(b) i=2 j=2

Q-12 For what values of x the "Point 3" only will be printed
if(x>4) { System.out.println("Point1"); }
else if(x>9 ) { System.out.println("Point 3"); }
else { System.out.println("Point 3"); }

(a) x is less than zero
(b) between 0 and 4
(c) greater than 4
(d) none

Q-13 ow can you represent 7 in exadecimal ___

Q-14 hat is return type of method in Actionlistener

Q-15 hat is the arguments passed for methods in MouseMotionListener ?

Q-16 For the following code snippet which expression will result true ?
nteger A = new nteger(10);
nteger B = new nteger(10);
Float f = new Float(10.0f);
int x = 10;
long y = 10L;
nteger c = b;
(a) if(c==b)
(b) if(a==b)
(c) if(a.equals(10));
(d) if(x==a)
(e) if(x==y)

Q-17 Parent
| |
Derived1 Derived2

Parent p1;
Derived1 d1;
Derived2 d2;

All of above given class are not null;

(a) compile error
(b) runtime error
(c) compiles and runs without Exception


Q-18

class Abc{
int x,y,z;
public Abc(int a , int b) {
x= a;
y= b;
}
public Abc(int a, int b, int c) {
//point 1
z =c;
}
}
n order to initialize x and y in second constructor write shortest possible way at
point 1

Q-19

hat is output of following code
class StackTest{
static Stack s1,s2;
public static void main(String a[]){
s1 = new Stack();
s1.push(new nteger(100));
amethod(s1);
System.out.println(" s1 is " + s1 + "\n s2 is " + s2);
}
public static void amethod(Stack s1){
s2=s1;
}
}
(a) s1 is [100]
s2 is []
(b) s1 is [100]
s2 is [100]
(c) compile error
(d) runtime error

Q-20 f you resize a component horizontally you need to add the component

(a) to the north and south of BorderLayout
(b) to the east and west of BorderLayout
(c) to the FlowLayout
(d) to east and north of BorderLayout

Q-21 hich are the correct class declarations ? Assume in each case text
constitutes of a file called Car.java on a system with a case significant
FileSystem.

(a) public class Fred{
(b) public class fred{
(c) public class Fred extends Abc,Xyz{
(d) public class Fred extends Objec{

Q-22 valid java keywords

q-23 legal identifiers

Q-24 after creating thread which method make that thread eligible to run _____ .

Q-25 what is range of char 0 to (2 raiseto 16) -1

Q-26 At which line in following code object created at line 3 becomes garbage
collected

Q-27 hich interface impose no order, no restrictions and no content duplication
?
(a) Set
(b) Map
(c) List
(d) Collection

Q-28 hen you resize window row changes its height vericatically . what is to be
given
(a) weightx
(b) gridx
(c) gridy
(d) weighty

Q-29 what constraints effects size of GridbagLayout.
(a) fill
(b) gridx
(c) gridy
(d) anchor
Q-30 Specify true or false
(a) it is in programmers hand to explicitly invoke garbage collection and
frees memory
when required.


Preparation Topics
Questions are:
1. What is the return type oI main() method?
2. What is the range oI int primitive type in Java?
3. What is the argument type oI all the methods in Mouse Listener interIace?
4. What is the range oI Char primitive type in Java?
5. Select the valid Java identiIiers Irom the list.
6. Select Irom the list those, which are NOT Java keywords.
7. How to add a button in a Irame so that height oI the button is dependent on the Irame, but width is not?
8. How will you represent the number 7 as an octal literal, using not more than Iour characters?
9. What modiIier you should use iI you don't want the method to be overridden in a subclass?
10. equals() on wrapper class. How it works?
11. Which is the earliest point in the given method, where Garbage Collection can be done?
12. What is the exact behavior oI passing "reIerences to objects" as method parameters?
13. Immutability oI String
14. Explicit casting during object reIerence assignment.
15. Short circuit operators, compare them with logical & and ,
16. "while" loop. Question to test that it may not get executed even once iI the condition is Ialse in the
beginning itselI.
17. Labeled "Continue". Question to test that where Ilow goes when "continue" with a label is encountered?
18. "switch" statement. Question to test the "Iall-through" nature oI "switch" structure.
19. "II()} else iI()}" to test mutual exclusiveness oI code blocks
20. Signature oI a subclass: importance oI "extends".
21. Thread: What will stop it Irom executing?
22. What does the getid() method oI AWT subclass return?
23. What are the possible signatures oI methods in the given options, allowed in a subclass, given a method
in superclass.
24. Characteristics oI Garbage Collection in Java
25. Which all keywords Irom the given list needed to declare instance variables oI the given class
deIinition?
26. Given a class deIinition, what is allowed above it in the code? From the list package, import, other class
signature etc.
27. Which element oI args array oI main will contain the speciIic command line argument?
28. Class, subclass deIinitions and calling. Syntax error line identiIication.
29. What all Irom the given list a container can contain?
30. Event handling and multiple listeners Ior a component.
31. Valid declaration type Ior a two dimensional array.
32. Constructor argument Ior FilterInputStream
33. A constructor calling this() in the same class.
34. Two ways to construct Threads. (1. extends and 2. implements)
35. Which collection can have ordered items but repetitions allowed?
36. Gridbaglayout parameter characteristics.(weightx and weighty)
37. Adapter classes Ior event handling.
38. Array declaration (without initialization) in main() what will be printed iI array elements are to be
printed?
39. With an instance variable oI a class without the class getting instantiated getting reIerred in main.
40. What is the return type oI listener?
41. Exception handling: To test that Iinally always gets executed.
42. What will be the output, when a Irame declaration and description without using a separate class Ior
that, is done in main()?
43. Compare and contrast oI ~~ and ~~~
44. In a case sensitive operating system, what are the valid class signatures given the source code Iile
name?
45. Valid inner class declaration and instantiation at same place.
46. "Throws" and "throw" syntax.
47. Final contents oI a string aIter concat, toUppercase etc. without assigning to other string or overwriting,
and then Iinally with operator.
48. Ideal conditions Ior total encapsulation.
49. Math object`s Iloor, ceil and round.
50. DeIault scope oI class (package level or Iriendly as it is called without a modiIier).
51. How to declare a native method?
52. At a given point (place) in code, which all assignment statements valid, Irom the given list?
53. Access oI variables between inner and outer classes(which variables can the inner class access)
54. Name oI the method used to schedule a Thread Ior execution.
55. From the given list, which all are valid abstract class signatures.
56. From a given list, which statement is true about a non-static inner class?
57. From the list given, what can cause a thread to stop execution?
58. The modiIier 'synchronized Ior object locking.
59. Casting questions to see when the code produces a runtime error and when a compile error

Vous aimerez peut-être aussi