JCP Mocks
JCP Mocks
JCP Mocks
com 1
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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 Which 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) When 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 What is wrong with the following code?
Class MyException extends Exception{}
Public class Test {
public void foo() {
try{ bar(); }
finally { baz(); } catch (MyException e) {} }
(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 What 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 doIt() in a class Work represents work to be done, what block
of code will succeed in starting a new thread that will do the work?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 2
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(a) Runnable r = new Runnable(){ Public void run(){ Work.doIt(); } };
Thread t new Thread( r );
t.start();
(b) Thread t new Thread(){ public void start(){Work.doIt(); }};
t.start();
(c) Runnable r = new Runnable() { Public void run(){ Work.doIt(); } }; r.start();
(d) Thread t new Thread( new Work()) ; t.start();
(e) Runnable t = new Runnable() { Public void run(){ Work.doIt(); } }; t.run();
Q6 Write 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 What will be the result of compiling and running the following code?
Public class Test {
static int a;
int b;
Public Test1
{ Int 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 What 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 Which statements are true concerning the default layout manager for containers in the
java.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
Q10 Which 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)
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 3
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(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 waitforId() in class MediaTracker is called
(b) The run() method that the Thread is executing ends
(c) The call to the start() method of the Thread object returns
(d) The suspend() method is called on the Thread object
(e) The wait() method is called on the Thread object
Q12 When 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
Q13 What does the value returned by the method getID() found in class java.awt.AWTEvent
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
Q14 What 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
Q15 Which 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) ()
Q16 How does the weighty property of the GridBagConstraints objects used in grid bag layout
affect the layout of the components?
(a) If affects which grid cell the components end up in
(b) If affects how the extra vertical space is distributed
(c) If affects the alignment of each components
(d) If affects whether the components completely fill their allotted display area vertically
Q17 Which statement can be inserted at the indicated position in the following code to make
the program write 1 on the standard output when run?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 4
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Public class Test{
Int a = 1 ;
Int b = 1 ;
Int c = 1 ;
Class Inner{
Int a = 2 ;
Int get() {
int c = 3 ;
// insert statement here
return c;
} }
Test () {
Inner I = new Inner()
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;
Q18 Which 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)
} }
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 5
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Q20 Which 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 Which of these are keywords in Java?
(a) Default
(b) NULL
(c) String
(d) Throws
(e) Long
Q22 It 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. How 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
Q23 Which 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) Int[] [] tab = { {0,0,0}, {0,0,0}};
(b) Int tab[] [] = new int[4][]; for(int I=0, I<tab.length; I++) tab[I] = new int[3];
(c) Int tab[][]= {
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0};
(d) Int tab [3][2];
(e) Int [] tab[]= { {0,0,0}, {0,0,0},{0,0,0},{0,0,0}};
Q24 What 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 ArrayIndexOutOfBoundException
(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
Q25 Which expressions will evaluate to true if preceded by the following code?
String a = “hello”;
String b = new String(a);
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 6
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
String c = a;
Char[] d = {‘h’,’e’,’l’,’l’,’o’};
(a) (a == “Hello”)
(b) (a == b)
(c) (a == c)
(d) a.equals(b)
(e) a.equals(d)
Q26 Which statements concerning the following code are true?
Class A {
public A() {}
public A(int I) { 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 I) {}
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 7
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Q29 Which 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 Which 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
Q31 Which 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[]){
If (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 (ArrayIndexOutOfBoundsException e) {}
}
(c) Public static void main(String args[]) {
Int ix = args.length;
String last = args[ix];
If (ix > 0) System.out.println(last);
}
(d) Public static void main(String args[]) {
Int ix = args.length-1;
If (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) {}
}
Q32 Which of the following statements concerning the collection interfaces are true?
(a) Set extends Collection
(b) All methods defined in Set are also defined in Collection
(c) List extends Collection
(d) All method defined in List are also defined in Collection
(e) Map extends Collection
Q33 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
Q34 What is the name of the method that threads can use to pause their execution until
signalled to continue by another thread?
(a) Wait
(b) Suspend
(c) Stop
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 8
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(d) All of the above
Q35 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)
Q36 What 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;
Int 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
Q37 What will be written to the standard output when the following program is run
Public class Test{
Int a;
Int b;
Public void f() {
A = 0;
B=0;
Int [] 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
Q38 Which 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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 9
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(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?
Import java.awt. ;
Public class Test{
public static void main(String args[]) {
Window win = new Frame();
Button but = new Button(“button”);
// insert code fragment here
win.setSize(200,200);
win.setVisible(true);
} }
(a) Win.setLayout(new BorderLayout());
Win.add(but);
(b) Win.setLayout(new GridLayout(1,1));
Win.add(but);
(c) Win.setLayout(new BorderLayout( ));
Win.add(but.BorderLayout.CENTER);
(d) Win.add(but);
(e) Win.setLayout(new FlowLayout());
Win.add(but);
Q40 Which method implementations will write the given string to a file named “file”, using UTF8
encoding?
(a) Public void write(String msg) throws IOException{
FileWriter fw = new FileWriter(new File(“file”));
Fw.write(msg);
Fw.close();
}
(b) Public void write(String msg) throws IOException{
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(“file”),
“UTF8);
Osw.write(msg);
Osw.close();
}
(c) Public void write(String msg) throws IOException{
FileWriter fw = new FileWriter(new File(“file”));
Fw.setEncoding(“UTF8);
Fw.write(msg);
Fw.close();
}
(d) Public void write(String msg) throws IOException{
FilterWriter fw = new FilterWriter(new FileWriter(“file”),”UTF8”);
Fw.write(msg);
Fw.close();
}
(e) Public void write(String msg) throws IOException{
OutputStreamWriter osw = new OutputStreamWriter(new OutputStream(new
File(“file”)), UTF8);
Osw.write(msg);
Osw.close();
}
Q41 Which are the valid identifiers?
(a) _class
(b) $value$
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 10
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(c) zer@
(d) angstrom
(e) 2much
Q42 What will be the output of attempting to compile and run the following program?
Public class Test{
Public static void main(String args[]) {
Int counter = 0;
L1:
For(int i = 10; I<0;I++){
L2:
Int j = 0;
While(j<10) {
If (j > 1) break L2;
If ( 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
Q43 Given the following definition, which definitions are valid?
Interface I {
void setValue(int val);
Int getValue(); }
(a) Class A extends I {
Int value;
Void setValue(int val) {value = val;}
Int getValue(){return value;} }
(b) Interface B extends I {
void increment(); }
(c) Abstract class C implements I {
Int getValue(); { return 0; }
Abstract void increment(); }
(d) Interface D implements I {
void increment(); }
(e) Class E implements I {
Int value ;
Public void setValue(int val) {value = val ;} }
Q44 Which statements concerning the methods notify() and notifyAll() are true?
(a) Instances 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) When 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
Q45 Which statements concerning the correlation between the inner and outer instances of
non-static inner classes are true?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 11
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(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
Q46 What will be the result of attempting to compile and run the following code?
Public class Test{
Public static void main(String args[]) {
Int I = 4;
Float f = 4.3;
Double d = 1.8;
Int c = 0;
If ( I == f ) c++;
If ((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
Q47 Which operators will always evaluate all the operands?
(a) | |
(b) +
(c) &&
(d) ? :
(e) %
Q48 Which statements concerning the switch construct are true?
(a) All switch statements must have a default label
(b) There must be exactly one label for each code segment in a switch statement
(c) The keyword continue can never occur within the body of a switch statement
(d) No case label may follow a default label within a single switch statement
(e) A character literal can be used as a value for a case label
Q49 Which 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) Int
(e) Abstract
Q50 What 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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 12
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Q51 Which statements concerning the event model of the AWT 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 java.awt.event
(d) There exists a class named MouseMotionEvent in package java.awt.event
(e) There exists a class named ActionAdapter in package java.awt.event
Q52 Which 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 IOException will be thrown if a file named “data” already exists
(c) An IOException will be thrown if a file named “data” does not already exist
(d) If a file named “data’ exists, its contents will be reset and overwritten
(e) If a file named “data’ exists, its output will be appended to its current contents
Q53 Given the following code, write a line of code that, when inserted at the indicated location,
will make the overriding method in Extension 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 here
} }
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
Q54 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();
Q55 What 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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 13
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Q56 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{
Int v = 0;
Synchronized void inc() { v++; }
Synchronized void dec() { v- -; }
}
public class Test{
Counter I, 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();
}
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 14
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(e) Char ch = “A” ;
Q60 Given the following code, which of these constructors could be added to the MySubclass
without causing a compile time error?
Class MySuper{
Int number ;
MySuper(int i ) {number = i ;}
}
class MySub extends MySuper {
int count;
MySub(int cnt, int sum) {
Super(num);
Count = cnt ;
}
// insert additional constructor here
}
(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 Which 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) If 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) If 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) If 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?
Q62 What 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) It will simply print Test
(b) It will print Test followed by Test
(c) It will print 123 followed by Test
(d) It will print 12 followed by Test
(e) It will print 4 followed by Test
Q63 Given the following variable declaration within the definition of an interface which of these
declarations are equivalent to it?
Int answer = 42;
(a) Public static int answer = 42;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 15
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(b) Public final int answer = 42;
(c) static final int answer = 42;
(d) Public int answer = 42;
(e) All of the above
Q64 What is wrong, if anything, with the following code?
Abstract class MyClass implements Interface1, Interface2 {
Void f() { } ;
Void g() { } ;
}
interface Interface1 {
int VAL_A = 1 ;
int VAL_B = 2 ;
void f() ;
void g() ;
}
interface Interface2 {
int VAL_B = 3 ;
int VAL_C = 4 ;
void g() ;
void h() ;
}
(a) Interface1 and Interface2 do not match, therefore MyClass cannot implement them
both
(b) MyClass only implements Interface1. Implementation for void h() from Interface2 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
Q65 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
Q66 Which is the first line that will cause compilation to fail in the following program?
Class Test {
Public static void main(String args{}){
Test a ;
SubTest b ;
A = new test(); // (1)
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 16
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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)
Q67 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))
Q68 What 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
Q69 Given the following code, which statements are true?
Public interface HeavenlyBody{ String describe(); }
Class Star implements HeveanlyBody{
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 has-a star
(c) The code will fail to compile if the name starName is replaced with the name
bodyName throughout the Star class definition
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 17
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(d) the code will fail to compile if the name starName is replaced with the name name
throughout the Star class definition
(e) An instance of Planet is a valid instance of a HeavenlyBody
Q70 What 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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 18
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10
A,B,C, A,B,E D E A C E C B,D D,E
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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 19
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
(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 ItemEvents to
ItemListenters
(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
Q10 The JSlider class
(a) Is 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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 20
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 21
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 22
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Answers:
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10
C B A B D C A A A B
A11 A12 A13 A14 A15 A16 A17 A18 A19 A20
A A C D B A A B C B
A21 A22 A23 A24 A25 A26 A27 A28 A29 A30
D B A B C B D A A C
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 23
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
1. Which statement are characteristics of the >> and >>> operators.
C.
String s = "Example";
A. s >>> = 3;
B. s[3] = "x";
C. int i = s.length();
D. String t = "For " + s;
E. s = s + 10;
CDE.
String s = "hello";
A. s >> = 2;
B. char c = s[3];
C. s += "there";
D. int i = s.length();
E. s = s + 3;
CDE.
BC.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 24
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. An InterruptedException 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 waitforID() call on a MediaTracker.
ABDE.
You want to make this method throw an IOException if, and only if, the method
someTestFails() returns a value of true.
Which changes achieve this?
7. Which 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.
A. NULL
B. true
C. sizeof
D. implements
E. instanceof
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 25
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
DE.
A. (s==u)
B. (s==t)
C. (s.equals(t))
D. (s.equals(9))
E. (s.equals(new Integer(9))
CE.
10. Why 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. Which 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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 26
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
BCD.
11. You have the following code. Which 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
A. char a[][];
B. String a[];
C. String []a;
D. Object a[50];
E. String a[50);
F. Object a[];
BCF.
13. What 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 West of a BorderLayout
E. North or South of a BorderLayout
E.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 27
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
14. What might cause the current thread to stop executing?
A. An InterruptedException 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 InputStream
ABDE.
Non-runnable states:
String s = null;
AC.
String s = null;
ABCD.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 28
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can only be instantiated in the enclosing class
E. It can access any final variables in any enclosing scope.
E.
DE.
Where is it possible that the garbage collector will run the first time?
C.
20. Which 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?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 29
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
count ++;
D. int count = 0;
while (!(args[count].equals("")))
count ++;
A.
A. sizeof
B. abstract
C. native
D. NULL
E. BOOLEAN
BC.
22. Which 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.
E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 30
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
}
AE.
22. Which 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.
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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 31
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
23. Which 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.
C. import java.awt.*;
public class Test extends Object {
int x;
private Test (int xval) {
x = xval;
}
}
AC.
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 32
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
C. String a [5];
D. String [5] a;
E. String [] a = new String[5];
for (int i = 0; i < 5; a[i++] = null);
AB.
A. an Applet
B. a Component
C. a Container
D. a Menu
E. a Panel
D.
A. an Applet
B. a Panel
C. a Container
D a Container
E. a MenuItem
E.
A. InputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer
B.
A. File
B. InputStream
C. OutputStream
D. FileInputStream
E. RandomAccessFile
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 33
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B.
{
if (atest()) {
unsafe():
}
else {
safe();
}
}
DE.
30. Given a TextArea using a proportional pitch font and constructed like this:
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 34
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
public Example(int a, int b) {
/*do everything the same as single argument version of constructor
including assignment x = a */
y = b;
}
}
What is the most concise way to code the "do everything..." part of the
constructor
taking two arguments?
Answer:
this(a);
What is the most concise way to code the "do everything..." part of the
constructor
taking two arguments?
Answer:
this(a, b);
Warning! A similar question will appear with at least two classes, then it is
super("arguments"); that you should use.
CDE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 35
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
34. Given the following method body:
{
if (sometest()) {
unsafe();
}
else {
safe();
}
}
AD.
35. What would be the result of attempting to compile and run the following
piece of
code?
A.
35. What would be the result of attempting to compile and run the following
piece of
code?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 36
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A.
36. What would be the result of attempting to compile and run the following
piece of
code?
B.
37. What would be the result of attempting to compile and run the following
piece of
code?
38. What 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?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 37
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. a FlowLayout
B. a GridLayout
C. the center area of a BorderLayout
D. the East or West 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.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
C.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
A methods declares three variables as shown bellow and assign them non null
values.
Which of the following statements is correct for the following expression?
Parent p;
DerivedOne d1;
DerivedTwo d2;
p = d1;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 38
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
E. ....
C.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
A.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
A. Illegal both at compile and runtime. You cannot assign an object to a sibling
reference,
even with casting.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 39
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Which of the following statements is correct for the following expression?
B.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
A.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 40
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
C.
46. What would you use when you have duplicated values that needs to be
sorted?
A. Map
B. Set
C. Collection
D. List
E. Enumeration
D.
A. BufferedReader
B. ByteArrayReader
C. PrintWriter
D. InputStreamReader
E. ?????
D.
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. What is the return-type of the methods that implement the MouseListener
interface?
A. boolean
B. Boolean
C. void
D. Pont
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 41
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. When 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. ......
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.
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++) {
if (y==10){
<<<>>>}
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 42
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
}//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. What does it mean when the handleEvent() returns the true boolean?
A.
A.
55. What is the statement to assign a unicode constant CODE with 0x30a0?
Answer:
class StringTest {
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 43
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
if (<<>>) {}
}
}//class
Which 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.
A. %fred
B. *fred
C. thisfred
D. 2fred
E. fred
CE.
A. Employee
B. _Employee
C. %something
D. *something
E. thisemployee
A.B.E.
public class X {
<<>>
Which of the following statement return true for the <<>> line in
StringTest.class?
BD.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 44
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
59. Which code fragments would correctly identify the number of arguments
passed via
the command line to a Java Application?
A.
AC.
C.
A. TextField Enter
B. TextArea Enter
C. Scrollbar
D. MouseDown
E. Button
AE.
class SuperClass{
SuperClass(String s){}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 45
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
......
A. java.lang.ClassCastException
B. Wrong number of arguments in constructor
C. Incompatible type for =. Can't convert SubClass to SuperClass.
D. No constructor matching SuperClass found in class SuperClass.
BD.
Answer:
65. What 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 West of a BorderLayout
E. North or South of a BorderLayout
D. C.
66. What 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 West of a BorderLayout
E. North or South of a BorderLayout
E.C.
67. What 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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 46
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. FlowLayout
B. GridLayout
C. Center area of a BorderLayout
D. East or West of a BorderLayout
E. North or South of a BorderLayout
D.
A. NULL
B. sizeof
C. friend
D. extends
E. synchronized
DE.
D.
70. What 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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 47
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
E.
B.
A. b.m2();
B. g=b.f;
C. i=b.x;
D. i=b.y;
E. b.m(6);
ACDE.
Answer:
0x7
Answer:
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 48
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
07
A. -128–127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -232 – 232 -1
C.
A. ‘\u0000’ – ‘\uFFFF’
B. -32 768 – 32 767
C. -128 – 127
D. -231 – 231 -1
A.
A. 0 – 215-1
B. -32 768 – 32 767
C. - 2 16 – 216-1
D. 0 – 216-1
D.
A. 0 – 216-1
B. 0 – 232 -1
C. - 2 16 – 216-1
D. 0 – 216-1
D.
A. start()
B. run()
C. init()
D. suspend()
E. continue()
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 49
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
ADE.
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.
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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 50
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A.
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.
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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 51
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B.
85. You have been given a design document for a employee system for
implementation in
Java. It states.
bla bla bla
public
class
object
extends
Employee
Person
plus at least five more
Answer:
86. You have been given a design document for a polygon system for
implementation in
Java. It states.
A polygon is drawable, is a shape. You must access it. It should have values
in a vector
bla bla
public
object
vector
drawable
color
plus some more
Answer:
87. You have been given a design document for a polygon system for
implementation in
Java. It states. A polygon is a Shape. You must access it. It has a vector and
corners bla
bla
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 52
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
choose between the following words: What will you write when defining the
class?
public
class
Polygon
object
extends
Shape
plus some more
Answer:
A.
B (not sure)
public classTest {
E.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 53
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
89.What happens hen you run the following program with the command:
D.
89.What happens hen you run the following program with the command:
D.
90. Which number for the argument must you use for the code to print cat?
A. 0
B. 1
C. 2
D. 3
E. none of these
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 54
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B.
91. Which number for the argument must you use for the code to print cat?
With the command:
A. 0
B. 1
C. 2
D. 3
E. none of these
A.
.......
String s;
s = "Hello";
t = " " + "my";
s.append(t);
s.toLowerCase();
s+= " friend";
System.out.println(s);
Answer:
hello my friend
93. What will happen when you attempt to compile and run this code?
char k=10;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 55
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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;
}
}
}
D.
94. What will happen when you attempt to compile and run the following code?
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 56
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
95. Which 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.
CD.
97. If 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. If 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. Which of the following are correct methods for initializing the array
"dayhigh" with 7
values?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 57
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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.
ABE.
100. Assume that val bas been defined as an int for the code below.
AB
void myMethod(){
try{
fragile() ;
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 58
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
catch(NullPointerException npex){
A. "NullPointerException thrown"
B. "Exception thrown"
C. "Done with exceptions"
D. "myMethod is done"
E. Nothing is printed
BCD.
D.
A. start()
B. init()
C. begin()
D. run()
A.
104. Which statements on the <<< call >>> line are valid expressions?
public int x;
int y;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 59
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
public void m1( int a ) {
}
SuperClass( ) {
}
}
private float f;
void m2(int c) {
int x;
return;
}
SubClass() {
}
}
class T {
A. b.m2();
B. g=b.f;
C. I=b.x;
D. I=b.y;
E. b.m1(6);
F. g=b.x;
testa.
A. -128–127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -232 – 232 -1
A.
A. -27 – 27 -1
B. -2 15 – 215 -1
C. -231 – 231 -1
D. -263 – 263 -1
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 60
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A.
107. What would be the result of attempting to compile and run the following
piece of
code?
A.
108. Which 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.
A. NULL
B. TRUE
C. sizeof
D. implements
E. synchronized
DE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 61
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Which 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
H. i = 1, j = 2
I. i = 2, j = 2
AB.
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
H. i = 3, j = 2
AD.
A. public
B. none
C. private
D. .....
B.
113. You want the program to print 3 to the output. Which of the following
values for x
will do this?
Code:
switch(x){
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 62
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
case(1):
System.out.println("1");
case(2):
case(3):
System.out.println("2");
default:
System.out.println("3");
}
A1
B2
C3
D4
ABCD.
114. You want the program to print 3 to the output. Which 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");
}
A1
B2
C3
D4
ABC.
116. You have been given a design document for an employee system for
implementation
in Java. It states.
A. Vector
B. Int
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 63
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
C. Date
D. Object
E. New employee e;
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. It states. A polygon is drawable. You must access it. It has a vector and
corners
bla bla
choose between the following words: What will you write when defining the
class?
public
class
Polygon object
extends
Shape
drawable
plus some more
Answer:
119. Threads: Which statements are true about threads stopping to execute?
C or D.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 64
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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. What will be on the output. No Exception is
thrown.
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");
}
A. 1
B 1b
C. 3
D. 4
E. 5
ABDE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 65
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
121b. Consider the following code. What will be on the output. No Exception is
thrown.
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");
}
A. 1
B 1b
C. 3
D. 4
E. 5
ACDE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 66
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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. What are the characteristics of a totally encapsulated class? One answer.
D.
A. n==i
B. n==k
C. n.equals(k)
D. n.equals(7)
E. n.equals(new Integer(7))
CE.
125. Write 7 in hexadecimal. Do not use more than four characters and do no
assignment.
Answer:
0x7, 0x07
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 67
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
126. Consider the classes defined below:
import java.io.*;
class Super{
BC.
import java.io.*;
class Super{
Which of the following are legal method declarations to add to the class Sub?
Assume that
each method is the only one being added.
ABE.
A.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 68
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
129. Which object will be created when you implement a KeyListener? Unsure
about how
the question was formulated!!
Answer:
Answered KeyEvent
130 Which 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. ...
A class x{}
B
C myInterface (String x){
D myInterface () {
132. One Superclass and one Subclass. One was public and one was default.
How do you
create a new instance?? Unsure of the formulation of the question.
A. new Inner()
B. new Outer().new Inner()
C. .....
D. ......
B.
A. niceIdentifier
B. 2Goodbajs
C. %hejpådig
D. _goddag
E. Hello2
ADE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 69
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. It must implement an interface.
B. It is accessible from any other class.
C. It can only be instantiated in the enclosing class.
D. It must be final if it is declared in a method scope.
E. It can access any final variables in the enclosing class
E.
136. A question with some wrong code. What must you do to correct. I
changed to the
static modifier.
String s = "Svenne";
int i = 1;
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.
AB.
139. You are going to read some rows one by one from a file that is stored
locally on your
hard drive. How do you do it?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 70
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. BufferedReader
B. InputStreamReader
C. One reader with "8859-1" as an argument
D. Don't remember
E. FileReader
140. What is a correct argument list for a public static void main method?
AC.
int x = 1;
if (0 < x--){
System.out.println(x);
}
}
A. 0
B. 1
C. 2
D. Nothing
E. An IllegalArgumentException will be thrown
A.
int x = 1;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 71
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
if (0 < x--){
System.out.println(x);
}
}
A. 0
B. 1
C. 2
D. Nothing
E. An IllegalArgumentException will be thrown
D.
C.
A array
B boolean
C Integer
D protect
E super
BE.
A. 50
B. 49
C. '\u0000'
D. '\u0020'
E. ""
F. cannot be determined
G. always null until a value is assigned
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 72
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
145. Which identifiers are valid?
A. _xpoints
B. U2
C. blabla$
D set-flow
E. something
ABCE.
Answer:
147. Which of the following statements assigns "Hello Java" to the String
variable s?
AD.
148. An integer, x has a binary value (using 1 byte) of 10011100. What 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.
String s = "Hello";
String s2 = "Java";
s.concat( s2 );
A. True
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 73
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B. False
B.
150. If you compile and execute an application with the following code in its
main()method:
if ( s == "Computer" )
System.out.println ("Equal A");
if( s.equals( "Computer" ) )
System.out.println ("Equal B");
A. It will not compile because the String class does not support the = =
operator.
B. It 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.
byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;
A. myInt = myByte;
B. myInt = myLong;
C. myByte = 3;
D. myInt = myChar;
E. myFloat = myDouble;
F. myFloat = 3;
G. my Double = 3.0;
BE.
class MyPoint {
void myMethod(){
int x, y;
x = 5; y = 3;
System.out.print("(" + x + ", " + y + ")");
switchCoords(x,y);
System.out.print("(" + x + ", " + y + ")");
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 74
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
C.
AD.
154. If arr[] contains only positive integer values, what does this function do?
D.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 75
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
for(int n = 0; n < 4; n++)
System.out.println ( /*What will work here? */);
Which 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.
C.
int one = 1;
int two = 2;
char initial = '2';
boolean flag = true;
CDEG.
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");
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 76
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A. P
B. Q
C. R
D. S
AB.
Answer:
InterruptedException
m = 0;
while( m++ < 2 )
System.out.println(m);
A. 0
B. 1
C. 2
D. 3
E. Nothing and an exception is thrown
BC.
m = 0;
while( ++m < 2 )
System.out.println(m);
A. 0
B. 1
C. 2
D. 3
E. Nothing and an exception is thrown
B.
class Tree{}
class Pine extends Tree{}
class Oak extends Tree{}
public class Forest {
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 77
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
public static void main (String [] args){
Tree tree = new Pine():
else
System.out.println ("Oops ");
}
}
A. Pine
B. Tree
C. Forest
D. Oops
E. Nothing will be printed
ABD.
163. Which of the following statements about Java's garbage collection are
true?
BC.
164. What line of code would begin execution of a thread named myThread?
Answer:
myThread.start();
A. wait()
B. run()
C. stop()
D. update()
E. resume()
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 78
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Answer:
Object.
ABCE.
A. equals( s )
B. substring( s )
C. concat( s )
D. toUpperCase ( s )
E. none of the above will change s
E.
String sl = "phenobarbital";
String s2 = s1.substring( 3, 5 );
A. null
B. "eno"
C. "enoba"
D. "no"
D.
170. What method(s) from the java.lang.Math class might method() be if the
statement
method( -4.4 )== -4; is true.
A. round()
B. min()
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 79
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
C. trunc()
D. abs()
E. floor()
F. ceil()
AF.
A. sin( )
B. cos( )
C. tan ( )
D. aSin ( )
E. Cos ( )
F. aTan( )
G. toDegree ( )
ABC.
AD.
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
MenuItem. Which one?
A. setVisible (boolean b)
B. setEnabled (boolean b)
C. getSize ()
D. setForeground (Color c)
E. setBackground (Color c)
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 80
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B.
175. If a font with variable width is used to construct the string text for a
column, the
initial size of the column is:
B.
176. Which 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 AWT classes, which one(s) are responsible for
implementing the
components layout? Select all.
A. LayoutManager
B. GridBagLayout
C. ActionListener
D. WindowAdapter
E. FlowLayout
BE.
178. A component that should resize vertically but not horizontally should be
placed in:
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 81
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
179. What type of object is the parameter for all methods of the MouseListener
interface?
Answer:
MouseEvent
180. What type of object is the parameter for all methods of the
MouseMotionListener
interface?
Answer:
MouseEvent
181. What type of object is the parameter for all methods of the KeyListener
interface?
Answer:
KeyEvent
182. What type of object is the parameter for all methods of the ActionListener
interface?
Answer:
ActionEvent
183. Which of the following statements about event handling in JDK 1.1 and
later are true?
Select all.
AC.
184. Which of the following describe the sequence of method calls that result
in a
component being redrawn?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 82
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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. DataInputStream
B. InputStream
C. RandomAccessFile
D. File
E. None of the above
C.
A. File
B. DataOutput
C. Directory
D. FileDescriptor
E. FileOutputStream
A.
raf.seek(raf.length());
D.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 83
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
189. Consider the following code: What will be printed?
try{
System.out.println("1");
problem();
}
System.out.println("2");
return;
}
catch(Exception x){
System.out.println("3");
return;
}
finally{
System.out.println("4");
}
System.out.println("5");
}
1
2
3
4
5
ACD.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 84
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
public static void main(String[] args){
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.
try{
System.out.println("Innan testet");
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 85
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
problem();
}
System.out.println("Nullpointer");
catch(Exception x){
System.out.println("Exception");
return;
}
finally{
System.out.println("finally");
}
System.out.println("mymethod is done");
}
Innan testet
Nullpointer´
Exception
finally
mymethod is done
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 86
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
finally{
System.out.println("Done with exceptions ");
}
System.out.println("myMethod is done");
}
NullpointerException thrown
Exception thrown
Done with exceptions
D.myMethod is done
A. –128 – 127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -263 – 263 -1
B.
-128 – 127
-231 – 231 –1
C. -215 – 215 -1
D. -263 – 263 -1
C.
-128 – 127
-231 – 231 –1
C. -215 – 215 -1
D. -263 – 263 -1
D.
int i = 10;
int j;
char z = 823;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 87
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
char q = '1';
boolean b;
static int k = 9;
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.
String s = "Hello";
char c ='H';
s+=c;
System.out.println(s);
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 88
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
198. Consider the following code: What will be printed?
C.
null
0
Nothing will be printed. Compilation error.
Compiles just fine, but a RuntimeException will be thrown.
A.
void amethod(){
int K[] = new int[4];
System.out.println(K[3]);
}
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 89
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B. null 0 0
C. 0 0 null
D. 0 null 0
C.
class Arraytest2{
123
003
023
000
B.
0000
00
0
0000000000000000
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 90
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
test2();
}
if(flag=true){
System.out.println("true");
else {
System.out.println("false");
}}
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.
A.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 91
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
C. What makes the difference here is the new operator. You get fooled and
think that s =
= t and x = = u would return false.
boolean b1 = false;
A. Nothing will be printed. You must use the word args instead of kyckling in
the main
method.
We are equal 10
Not equal 10
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 92
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
We are equal 20
Not equal 20
C.
john == john
"john" == "john" "john".equals "john"
john == john john.equals john
john.equals john
"john" == "john"
"john".equals "john"
B.
if (A == 4096)
System.out.println("Equal");
System.out.println(A);
int B = (int)4096;
if (B == 4096)
System.out.println("Equal");
System.out.println(A);
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 93
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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.
New value is 30
New value is 31
New value is 1
New value is null
A.
System.out.println(i);}
}}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 94
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
0123456789
Compiler error. Constructor cannot be protected.
1 2 3 4 5 6 7 8 9 10
D.
E.
213. Consider the following code: What will happen when you try to compile it?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 95
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
{}
public class MyInner{
}}
A.
C.
215. If you're stupid and program like this. What will happen?
byte b = (byte)259;
short s = (short)b;
}
}
short s = 3 + byte b = 3
short s = 3 byte b = 3
short s = 3 byte b = 259
Nothing will be printed. Illegal explicit cast.
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 96
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
216. If you're stupid and program like this. What will happen?
public class LoseInformationCast{
public static void main(String[]args){
short s = 259;
byte b = (byte)s;
System.out.println("short s =" + s + "= byte b = " + b);
}
}
B.
else if (x==17)
System.out.println("3");
else if (x==18)
System.out.println("4");
System.out.println("0");
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 97
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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");
}
A.
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 98
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
12
null
Error you cannot initialize a non-static variable in the main method.
0
A.
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 99
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
}
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.
}}}
LongEqualsInteger.
If you create new primitive values of Long(4096) and Integer(4096), then ==
true.
LongEqualsInteger. If you create new primitive values of Long(4096) and
Integer(4096),
then == true.
If you create new primitive values of Long(4096) and Integer(4096), then ==
true.
Nothing will be printed.
B.
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");
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 100
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
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.
0
null
Error. Non-static variable i cannot be referenced from a static context.
Error. Variable I may not have been initialized.
C.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 101
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
System.out.println(st.indexOf('A', 2));
System.out.println(st.indexOf('G'));
System.out.println(i);
}
}
abc
azzz bc def
2
0
-1
-1
a b cABCDE
abc
abc def zzz
2
0
-1
-1
a b c ABCDE
C.
abc
abcdefzzz
2
0
1
-1
a b c ABCDE
D.
abc
a zzz bc def
2
0
-1
-1
a b cABCDE
D.
if (sb1.equals(sb2))
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 102
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
System.out.println("Equals");
else
if (s1.equals(s2))
System.out.println("String Equals");
else
System.out.println("Equals not");
}
}
Equals
Equals not
Equals
String Equals
D.
StringBuffer Equals not
Equals not
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 103
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 104
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
f.equals(a)
e.equals(c)
e!=c
A.
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. It 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);
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 105
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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);
}
}
if (a.equals(c)){
System.out.println("rätt");
}
}
}
Fel rätt
rätt
Fel
None will be printed. A NullPointerException will be thrown.
None will be printed. Compilation error. Incompatible types and a non-static
variable
cannot be referenced from a static context.
if (a==c){
System.out.println("Fel");
}
if (a.equals(c)){
System.out.println("rätt");
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 106
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
}
}
Fel rätt
rätt
Fel
None will be printed. A NullPointerException will be thrown.
None will be printed. Compilation error. Incompatible types and a non-static
variable
cannot be referenced from a static context.
None will be printed. Compilation error. Incompatible types.
F.
if (a==c){
System.out.println("Fel");
}
if (a.equals(c)){
System.out.println("rätt");
}
}
}
Fel rätt
rätt
Fel
None will be printed. A NullPointerException will be thrown.
None will be printed. Compilation error. Incompatible types and a non-static
variable
cannot be referenced from a static context.
None will be printed. Compilation error. Incompatible types.
B.
class Unchecked{
public static void main(String[]args){
try{
method();
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 107
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
catch (Exception e) {
System.out.println("Fångar Exception");
}
}
static void method(){
try{
method1();
System.out.println("Testar method1");
}
B.
class Unchecked1{
public static void main(String[]args){
}
void method(){
try{
metod1();
System.out.println("Testar metod1");
}
catch (ArithmeticException ae) {
System.out.println("Fångar ArithmeticException");
}
finally{
System.out.println("Kör finally");
}
System.out.println("I method() utanför finally");
}
void metod1(){
throw new NullPointerException();
}
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 108
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Updated by Sasa.
C.
String s = "Example";
A. s >>> = 3;
B. s[3] = "x";
C. int i = s.length();
D. String t = "For " + s;
E. s = s + 10;
CDE.
String s = "hello";
A. s >> = 2;
B. char c = s[3];
C. s += "there";
D. int i = s.length();
E. s = s + 3;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 109
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
CDE.
BC.
A. An InterruptedException 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 waitforID() call on a MediaTracker.
ABDE.
You want to make this method throw an IOException if, and only if, the method
someTestFails() returns a value of true.
Which changes achieve this?
7. Which modifier should be applied to a method for the lock of the object this
to be
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 110
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
obtained prior to executing any of the method body?
A. final
B. static
C. abstract
D. protected
E. synchronized
E.
A. NULL
B. true
C. sizeof
D. implements
E. instanceof
DE.
A. (s==u)
B. (s==t)
C. (s.equals(t))
D. (s.equals(9))
E. (s.equals(new Integer(9))
CE.
10. Why 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. Which numbers will cause "Test2" to be
printed?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 111
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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.
A. char a[][];
B. String a[];
C. String []a;
D. Object a[50];
E. String a[50);
F. Object a[];
BCF.
13. What 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 West of a BorderLayout
E. North or South of a BorderLayout
E.
A. An InterruptedException is thrown
B. The thread executes a sleep() call
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 112
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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 InputStream
ABDE.
Non-runnable states:
String s = null;
AC.
String s = null;
ABCD.
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can only be instantiated in the enclosing class
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 113
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
E. It can access any final variables in any enclosing scope.
E.
DE.
Where is it possible that the garbage collector will run the first time?
C.
20. Which 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?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 114
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A.
A. sizeof
B. abstract
C. native
D. NULL
E. BOOLEAN
BC.
22. Which 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.
E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}
AE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 115
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
23. Which 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.
C. import java.awt.*;
public class Test extends Object {
int x;
private Test (int xval) {
x = xval;
}
}
AC.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 116
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
E. The variable should be marked private and an accessor method provided
C.
C. String a [5];
D. String [5] a;
E. String [] a = new String[5];
for (int i = 0; i < 5; a[i++] = null);
AB.
A. an Applet
B. a Component
C. a Container
D. a Menu
E. a Panel
D.
A. InputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer
B.
A. File
B. InputStream
C. OutputStream
D. FileInputStream
E. RandomAccessFile
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 117
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
{
if (atest()) {
unsafe():
}
else {
safe();
}
}
DE.
30. Given a TextArea using a proportional pitch font and constructed like this:
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 118
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
/*do everything the same as single argument version of constructor
including assignment x = a */
y = b;
}
}
What is the most concise way to code the "do everything..." part of the
constructor
taking two arguments?
Answer:
this(a);
What is the most concise way to code the "do everything..." part of the
constructor
taking two arguments?
Answer:
this(a, b);
Warning! A similar question will appear with at least two classes, then it is
super("arguments"); that you should use.
CDE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 119
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
{
if (sometest()) {
unsafe();
}
else {
safe();
}
}
AD.
35. What would be the result of attempting to compile and run the following
piece of
code?
A.
36. What would be the result of attempting to compile and run the following
piece of
code?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 120
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B.
37. What would be the result of attempting to compile and run the following
piece of
code?
38. What 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 West 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.
class Parent {}
class DerivedOne extends Parent {}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 121
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
class DerivedTwo extends Parent {}
C.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
A.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 122
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
D. ....
E. ....
A. Illegal both at compile and runtime. You cannot assign an object to a sibling
reference,
even with casting.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
B.
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
A.
class Parent {}
class DerivedOne extends Parent {}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 123
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
class DerivedTwo extends Parent {}
C.
46. What would you use when you have duplicated values that needs to be
sorted?
A. Map
B. Set
C. Collection
D. List
E. Enumeration
D.
A. BufferedReader
B. ByteArrayReader
C. PrintWriter
D. InputStreamReader
E. ?????
D.
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 124
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
49. What is the return-type of the methods that implement the MouseListener
interface?
A. boolean
B. Boolean
C. void
D. Pont
C.
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 125
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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++) {
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. What does it mean when the handleEvent() returns the true boolean?
A.
A.
55. What is the statement to assign a unicode constant CODE with 0x30a0?
Answer:
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 126
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
class StringTest {
if (<<>>) {}
}
}//class
Which 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.
A. %fred
B. *fred
C. thisfred
D. 2fred
E. fred
CE.
public class X {
<<>>
Which of the following statement return true for the <<>> line in
StringTest.class?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 127
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
BD.
59. Which code fragments would correctly identify the number of arguments
passed via
the command line to a Java Application?
A.
AC.
C.
A. TextField Enter
B. TextArea Enter
C. Scrollbar
D. MouseDown
E. Button
AE.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 128
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
class SuperClass{
SuperClass(String s){}
}
......
A. java.lang.ClassCastException
B. Wrong number of arguments in constructor
C. Incompatible type for =. Can't convert SubClass to SuperClass.
D. No constructor matching SuperClass found in class SuperClass.
BD.
Answer:
65. What 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 West of a BorderLayout
E. North or South of a BorderLayout
D.
66. What 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 West of a BorderLayout
E. North or South of a BorderLayout
E.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 129
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
67. What 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 West of a BorderLayout
E. North or South of a BorderLayout
D.
A. NULL
B. sizeof
C. friend
D. extends
E. synchronized
DE.
D.
70. What 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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 130
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
C. It can only be instantiated in the enclosing class.
D. It must be final if it is declared in a method scope.
E. It can access private instance variables in the enclosing object.
E.
B.
A. b.m2();
B. g=b.f;
C. i=b.x;
D. i=b.y;
E. b.m(6);
ACDE.
Answer:
0x7
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 131
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Answer:
07
A. -128–127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -232 – 232 -1
C.
A. \u0000 – \uFFFF
B. -32 768 – 32 767
C. -128 – 127
D. -231 – 231 -1
A.
A. 0 – 215-1
B. -32 768 – 32 767
C. - 2 16 – 216-1
D. 0 – 216-1
D.
A. start()
B. run()
C. init()
D. suspend()
E. continue()
B.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 132
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
D. import java.awt.*;
E. package dum.util;
F. private int super = 1000;
ADE.
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.
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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 133
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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. It states.
bla bla bla
public
class
object
extends
Employee
Person
plus at least five more
Answer:
86. You have been given a design document for a polygon system for
implementation in
Java. It states.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 134
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A polygon is drawable, is a shape. You must access it. It should have values
in a vector
bla bla
public
object
vector
drawable
color
plus some more
Answer:
87. You have been given a design document for a polygon system for
implementation in
Java. It states. A polygon is a Shape. You must access it. It has a vector and
corners bla
bla
choose between the following words: What will you write when defining the
class?
public
class
Polygon
object
extends
Shape
plus some more
Answer:
A.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 135
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
B If 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)
public classTest {
E.
89.What happens hen you run the following program with the command:
D.
90. Which number for the argument must you use for the code to print cat?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 136
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
System.out.println(args[?]) ;
}
}
A. 0
B. 1
C. 2
D. 3
E. none of these
B.
91. Which number for the argument must you use for the code to print cat?
With the command:
A. 0
B. 1
C. 2
D. 3
E. none of these
A.
.......
String s;
s = "Hello";
t = " " + "my";
s.append(t);
s.toLowerCase();
s+= " friend";
System.out.println(s);
Answer:
hello my friend
93. What will happen when you attempt to compile and run this code?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 137
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
public static void main(String argv[]) {
MySwitch ms = new MySwitch();
ms.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;
}
}
}
D.
94. What will happen when you attempt to compile and run the following code?
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;
}
}
}
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 138
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
A.
CD.
CD.
97. If 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. If 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?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 139
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Answer:
private
99. Which 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.
ABE.
Q-1 int b1 = << 31;
int b2 = << 31;
b1 >>> = 31;
b1 >>> =1;
b2 >> = 31;
b2 >> = 1;
Q-2 Which of following expressions throws "Null Pointer Exception" given String S=null;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 140
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
// Point1
public class Xyz{
}
Q-6 In order to read a file line by line which is most preffered way
(a) FileInputStream fis = new FileInputStream("a.dat");
(b) DataInputStream dis = new DataInputStream(new FileInputStream("a.dat",r));
(c) DataInputStream dis = new DataInputStream(new FileInputStream("a.dat"));
(d) BufferedReader br = new BufferedReader(new FileReader("file");
Q-7 Intially "old.dat" file consists of 10 bytes of data after the following operation what is the length of the file
"old.dat" ?
(a) 8
(b) 14
(c) 4
(d) 20
(e) none
Q-10 If following method may throw IOException How do you declare the method in a proper way
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 141
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
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"); }
Q-16 For the following code snippet which expression will result true ?
Integer A = new Integer(10);
Integer B = new Integer(10);
Float f = new Float(10.0f);
int x = 10;
long y = 10L;
Integer 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;
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 142
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Derived1 d1;
Derived2 d2;
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;
}
}
In order to initialize x and y in second constructor write shortest possible way at point 1
Q-19
Q-20 If you resize a component horizontally you need to add the component
Q-21 Which 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.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 143
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Q-24 after creating thread which method make that thread eligible to run _____ .
Q-26 At which line in following code object created at line 3 becomes garbage collected
Q-28 When you resize window row changes its height vericatically . what is to be given
(a) weightx
(b) gridx
(c) gridy
(d) weighty
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 144
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
Preparation Topics
Questions are:
3. What is the argument type of all the methods in Mouse Listener interface?
6. Select from the list those, which are NOT Java keywords.
7. How to add a button in a frame so that height of the button is dependent on the frame, but width is not?
8. How will you represent the number 7 as an octal literal, using not more than four characters?
9. What modifier you should use if you don't want the method to be overridden in a subclass?
11. Which is the earliest point in the given method, where Garbage Collection can be done?
12. What is the exact behavior of passing "references to objects" as method parameters?
15. Short circuit operators, compare them with logical & and |
16. "while" loop. Question to test that it may not get executed even once if the condition is false in the beginning itself.
17. Labeled "Continue". Question to test that where flow goes when "continue" with a label is encountered?
18. "switch" statement. Question to test the "fall-through" nature of "switch" structure.
23. What are the possible signatures of methods in the given options, allowed in a subclass, given a method in superclass.
25. Which all keywords from the given list needed to declare instance variables of the given class definition?
26. Given a class definition, what is allowed above it in the code? From the list package, import, other class signature etc.
27. Which element of args array of main will contain the specific command line argument?
28. Class, subclass definitions and calling. Syntax error line identification.
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 145
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
29. What all from the given list a container can contain?
35. Which collection can have ordered items but repetitions allowed?
38. Array declaration (without initialization) in main() what will be printed if array elements are to be printed?
39. With an instance variable of a class without the class getting instantiated getting referred in main.
42. What will be the output, when a frame declaration and description without using a separate class for that, is done in
main()?
44. In a case sensitive operating system, what are the valid class signatures given the source code file name?
47. Final contents of a string after concat, toUppercase etc. without assigning to other string or overwriting, and then finally
with += operator.
50. Default scope of class (package level or friendly as it is called without a modifier).
52. At a given point (place) in code, which all assignment statements valid, from the given list?
53. Access of variables between inner and outer classes(which variables can the inner class access)
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?
Visit http://www.laynetworks.com
Downloaded form http://www.laynetworks.com : solutions@laynetworks.com 146
Do visit the site for the tones of information for the programmers and the newbies
Get Your Free Email Account of 6 MB form http://www.laynetworks.com
58. The modifier “synchronized” for object locking.
59. Casting questions to see when the code produces a runtime error and when a compile error
Visit http://www.laynetworks.com