Found these from one of the mocks
1) A sample question provided by Sun
What would be the result of attempting to compile and run the following piece of code?
public class
Test {
static int x;
public static void main (
String args[]) {
System.out.println("Value is " + x);
}
}
A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. An "illegal array declaration syntax" compiler error occurs.
D. A "possible reference before assignment" compiler error occurs.
E. An object of type ArrayIndexOutOfBoundsException is thrown.
2) A sample question provided by Sun
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
3) A sample question provided by Sun
Which is the advantage of encapsulation?
A.Only public methods are needed.
B.No exceptions need to be thrown from any method.
C.Making the class final causes no consequential changes to other code.
D.It changes the implementation without changing the interface and causes no consequential changes to other code.
E.It changes the interface without changing the implementation and causes no consequential
changes to other code.
4) A sample question provided by Sun
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
5) A sample question provided by Sun
Which statement is true about a non-static inner class?
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 private instance variables in the enclosing object.
6) A sample question provided by Sun
Which are keywords in
Java?
A.NULL
B.sizeof
C.friend
D.extends
E.synchronized
Select all valid answers.
7) A sample question provided by Sun
Which declares an abstract method in an abstract Java class?
A.public abstract method();
B.public abstract void method();
C.public void abstract Method();
D.public void method() {abstract;}
E.public abstract void method() {}
8) A sample question provided by Sun
Which code fragments would correctly identify the number of arguments passed via command line to a
Java application, excluding the name of the class that is being invoked?
A. int count = args.length;
B. int count = args.length - l;
C. int count=0;
while (args [count]!=null) count ++;
D. int count=0;
while(!(args[count].equals(""))) count ++;}
9) A sample question provided by Sun
FilterOutputStream is the parent class for BufferedOutputStream, DataOutputStream and
PrintStream. Which classes are a valid argument for the constructor of a FilterOutputStream?
A. InputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer
10) A sample question provided by Sun
Given the following method body:
1)
2) {
3) if (atest()) {
4) unsafe();
5) }
6) else {
7) safe();
8) }
9) }
The method "unsafe" might throw an AWTException (which is not a subclass of RunTimeException). Which
correctly completes the method of declaration when added at line one?
A. public AWTException methodName()
B. public void methodName()
C. public void methodName() throw AWTException
D. public void methodName() throws AWTException
E. public void methodName() throws Exception
11) A sample question provided by Sun
Given a TextArea using a proportional pitch font and constructed like this:
TextField t = new TextArea("12345", 5, 5);
Which statement is true?
A. The displayed width shows exactly five characters on each line unless otherwise constrained
B. The displayed height is five lines unless otherwise constrained.
C. The maximum number of characters in a line will be five.
D. The user will be able to edit the character string.
E. The displayed string can use multiple fonts.
11) A sample question provided by Sun
Given this skeleton of a class currently under construction:
public class Example {
int x, y;
public Example(int a) {
//lots of complex computation
x=a;
}
public Example(int a, int b) {
// do everything the same as single argument
// version of constructor
//including assignment x = a
y = b;
}
}
What is the most concise way to code the "do everything..." part of the constructor taking two
arguments?
Short answer, like "one(a)" ,do not add the semicolon at the end,
12) A sample question provided by Sun
Which correctly create a two dimensional array of integers?
A. int a[][] = new int[10,10]
B. int a[10][10] = new int[][];
C. int a[][] = new int [10][10];
D. int []a[] = new int [10][10];
E. int []a[] = new int[10][10];
Select all correct answers.
13) A sample question provided by Sun
Which are keywords in Java?
A. sizeof
B. abstract
C. native
D. NULL
E. BOOLEAN
Select all valid answers.
14) A sample question provided by Sun
Which are correct class declarations? Assume in each case that the text constitutes the entire contents of
a file called Fred.java on a system with a case-significant file system.
A. public class Fred {
public int x = 0;
public Fred (int x) {
this.x = x;
}
}
B. public class fred
public int x = 0;
public fred (int x) {
this.x = x;
}
}
C. public class Fred extends MyBaseClass, MyOtherBaseClass {
public int x = 0;
public Fred (int xval) {
x = xval;
}
}
D. protected class Fred {
private int x = 0;
private Fred (int xval) {
x = xval;
}
}
E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}
15) A sample question provided by Sun
A class design requires that a particular member variable must be accessible for direct access by any
subclasses of this class, but otherwise not by classes which are not members of the same package.
What should be done to achieve this?
A. The variable should be marked public
B. The variable should be marked private
C. The variable should be marked protected
D. The variable should have no special access modifier
E. The variable should be marked private and an accessor method provided
16) A sample question provided by Sun
Which correctly create an array of five empty Strings?
A. String a [] = new String [5];
for (int i = 0; i < 5; a[i++] = "");
B. String a [] = {"", "", "", "", ""};
C. String a [5];
D. String [5] a;
E. String [] a = new String [5];
for (int i = 0; i < 5; a[i++] = null);
17) A sample question provided by Sun
Which cannot be added to a Container?
A. an
Applet B. a Component
C. a Container
D. a Menu
E. a Panel
-Arun
:roll: :roll: