Download your free 5-user version! Download LANguard Internet/Network access control!
HOME|SUBMIT DUMP|SUBMIT NON-MS DUMP| MAIL TO Sasa
SUGGEST site to friend |LINKS |Please use dump for learning.

20000208-310-025-tho.htm Sun Certified Programmer for the Java 2 Platform
New Checkpoint  

T. Javaguru?

Java Programmer for the 2 Platform

This dump is my thanks to Sasa and Thomas Leuthard for providing the sites.
It is also a thanks to myTwoCents(SQL admin), Ecuador, Daniel and Russian(SQL impl), Ian (NT Server in the Enterprise), Shorty, Tow7, Johnny, XXX-man, Phil, and Deepred (NT Server) for their work.

Questions 1-140 are braindump questions collected from my brain, Sun´s site, two course mates and what we have found elsewhere on the internet (not so many though). 142-188 are a mix of a knowledge company´s free test. Many of the questions matched Sun´s questions exactly and seemed to be ripped directly from their test, and my own questions. 189-234 are my own questions from some of my simulations. I find them valuable enough to be on this page.

If you find errors, typographical or others, answers for instance, then please post it on this site and I will correct them.

I used a lot of sources. Java Exam Prep(good), Java Exam Cram (better) and Java Certifaction Study Guide(better). This was the hardest test I’ve taken so far, I’ve taken four MS’ exams after the Java test. From the the internet I used Marcus Green´s two Mock Exams, MindQ’s free Practice Test, Sun’s sample questions, ”The 30 1.0.2 questions”, Two of Boone’s old exams and John Hunt’s mock exam.

If you want more non-dump questions check out Marcus Green’s site.

http://www.software.u-net.com/javaexam/javaexam.htm
http://www.software.u-net.com/javaexam/javaexam2.htm

For some explanations on some of the questions posted here from the 1.0.2 exam check out:

http://home.worldonline.nl/~bmc88/java/javacert/newansw.html
http://home.worldonline.nl/~bmc88/java/javacert/newcert21-30.html
http://home.worldonline.nl/~bmc88/java/javacert/newcert11-20.html
http://home.worldonline.nl/~bmc88/java/javacert/newcert1-10.html

Here it is:

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

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

C.


2. Given the following declaration

String s = ”Example”;

Which are legal code?

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

CDE.


3. Given the following declaration

String s = ”hello”;

Which are legal code?

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

CDE.


4. Which statements are true about listeners?

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

BC.


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

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.


6. Given the following incomplete method.

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

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

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

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


7. 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.


8. Which are keywords in Java?

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

DE.


9. Consider the following code:

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

Which test would return true?

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?

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.


New Checkpoint  

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

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

BCF.


13. 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.


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:

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

From Certification Study Guide p. 227


15. Consider the following code:

String s = null;

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

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

AC.


16. Consider the following code:

String s = null;

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

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

ABCD.


17. Which statement is true about an inner class?

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.


18. Which statements are true about threads?

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

DE.


19. Consider the following code:

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

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

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

C.


20. 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?

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

A.


21. Which are keywords in Java?

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.

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

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

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

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

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

AE.


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


23. 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.

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

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

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


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

AC.


24. A class design requires that a particular member variable must be accesible for direct access by any subclasses of this class, otherwise not by classes which are not members of the same package. 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

C.


25. 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);

AB.


26. Which cannot be added to a Container?

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

D.


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

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

B.


28. FilterInputStream is the parent class for BufferedInputStream and DataInputStream. Which classes are a valid argument for the constructor of a FilterInputStream?

A. File
B. InputStream
C. OutputStream
D. FileInputStream
E. RandomAccessFile

B.


29. Given the following method body:

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

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

DE.


30. 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.

BD.


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

public class Example {
int x, y;

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

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

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

Answer:

this(a);


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

public class Example {
int x, y;

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

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

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.


33. 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];

CDE.


34. Given the following method body:

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

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

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

AD.


35. 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.

A.


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

public class Test {
public int x;

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

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

B.


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

public class Test {


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

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

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


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.


39. We have the following organization of classes.

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

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

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

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

C.


40. We have the following organization of classes.

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

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

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

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

A.


41. We have the following organization of classes.

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

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

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

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

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


43. We have the following organization of classes.

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

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

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

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

B.


44. We have the following organization of classes.

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

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

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

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

A.


45. We have the following organization of classes.

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

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

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

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

C.


46. 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.


47. What kind of reader do you use to handle ASCII code?

A. BufferedReader
B. ByteArrayReader
C. PrintWriter
D. InputStreamReader
E. ?????

D.


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


48. How can you implement encapsulation in a class?

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

B.


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

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

C.


50. What is true about threads that stop executing?
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. ......

C.


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

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

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

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

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

B.


52. Given this class ?

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

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

if (y==10){

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

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

B.


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

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

A.


54. What is the target in an Event?

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

A.


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

Answer:

public static final char CODE=‘\u30a0’;



56. The following code resides in the source?

class StringTest {

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

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.


57. Which are valid identifiers?

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

CE.


58. We have the following class X.

public class X {

public void method();

}

<<>>

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

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

BD.


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

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

A.


60. Given a TextField that is constructed like this:

TextField t = new TextField(30);

Which statement is true?

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

AC.


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

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

C.


62. When is an action invoked?

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

AE.


63. What error does the following code generate?

class SuperClass{

SuperClass(String s){}
}

class SubClass extends SuperClass{
SubClass(){}
}

......

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

A. java.lang.ClassCastException
B. 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.


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

Answer:

public native void myMethod();


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.


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.


68. Which are keywords in Java?

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

DE.


69. 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.

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.


71. 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.

E.


72. 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() {/}

B.


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

public class SuperClass {

public int x;
int y;

public void m1 (int a) {
}

Superclass(){
}
}

class SubClass extends SuperClass{

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

class T {

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

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

ACDE.


74. Type 7 in hexadecimal form.

Answer:

0x7


75. Type 7 in octal form.

Answer:

07


76. What is the range of an integer?

A. -128–127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -232 – 232 -1

C.


77. What is the range of a char?

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

A.


78. What is the range of a char?

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

D.


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

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

B.


80. What can you place first in this file?

//What can you put here?

public class Apa{}

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

ADE.


81. What is the output of the following code?

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

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

AC.


82. What is the output of the following code?

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

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

A.


83. How do you declare a native method?

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

B.


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

try{

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


A thrown 1
B thrown 2
C thrown 3
D none

BC.


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

choose between the following words:

public
class
object
extends
Employee
Person
plus at least five more

How should you name the class?

Answer:

public class Employee extends Person


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

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

Which variables should you use?

choose between the following words:

public
object
vector
drawable
color
plus some more

Answer:

vector, color (not sure)


87. You have been given a design document for a polygon system for implementation in Java. 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:

public class Polygon extends Shape


88. What is true about the garbage collection?

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

A.


87. What is true about a thread?

A The only way you can create a thread is to subclass java.lang.Thread
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)


88. What happens when you compile the following code?

public classTest {

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

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

E.


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

java Prog cat dog mouse

public class Prog {

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

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

D.


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

With the command:

java Prog dog cat mouse

public class Prog {

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

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

B.


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

java Prog cat dog mouse

public class Prog {

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

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

A.


92. You have the following code:

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

What will be printed?

Answer:

hello my friend


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

public class MySwitch{

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

public void amethod() {

char k=10;

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

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

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

D.


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

public class MySwitch{

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

public void amethod() {

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

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

A.


95. 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.


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


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

CD.


97. 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?

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

BC.


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

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

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

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

ABE.


101. Consider the code below.

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

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

What is printed to standard output if fragile() throws an IllegalArgumentException?

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

BCD.


102. A class design requires that a particular member variable must be accessible for direct access by classes which are members of the same package. 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

D.


103. Which method do you use to start a Thread?

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

A.


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

public class SuperClass {

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

SuperClass( ) {
}
}

class SubClass extends SuperClass {

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

class T {

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


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

testa.


105. What is the range of a byte?

A. -128–127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -232 – 232 -1

A.


106. What is the range of a byte?

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

A.


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

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

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

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.


109. Which are keywords in Java?

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

DE.


110. Consider the code fragment below:

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

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.


111. Consider the code fragment below:


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

Which of the following will be printed to standard output?

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

AD.


112. What is the modifier for events in EventListeners?

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

B.


113. You want the program to print 3 to the output. 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(”2”);
default:
System.out.println(”3”);
}

A 1
B 2
C 3
D 4

ABCD.


114. You want the program to print 3 to the output. 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”);
}

A 1
B 2
C 3
D 4

ABC.


115. A question about the GridbagLayout. One alternative.

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

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

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

Which variables should you use?

Answer:

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


117. You have been given a design document for a polygon system for implementation in Java. 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:

public class Polygon implements drawable


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

A. (Is it possible to have stack objects in a String) Code contained + "" + stack2 + "" +
B. (Is it possible to write stack1 = stack2;)
C. Prints bla bla bla
D. Prints bla bla
E. Prints bla bla


119. Threads: Which statements are true about threads stopping to execute?

A. All threads in the same class stop at the same time
B. The suspend() method stops the thread so that you can not start it again
C.
D.

C or D.


120. Which statements are true about garbage collection?
A. Garbage collection is predictable.
B. You can mark a variable or an object, (telling the system) so that it can be garbage collected
C. .....
D. .....

C or D.(not sure)


121. Consider the following code. What will be on the output. No Exception is thrown.

public class Mock2ExceptionTest{

public static void main(String [] args){

Mock2ExceptionTest e = new Mock2ExceptionTest();
e.trythis();
}

public void trythis(){

try{

System.out.println("1");
problem();
System.out.println("1b");
}

catch(Exception x){
System.out.println("3");

}

finally{
System.out.println("4");

}
System.out.println("5");
}


public void problem()throws Exception{

//throw not any Exception();
}
}

A. 1
B 1b
C. 3
D. 4
E. 5

ABDE.


No exception is thrown and everything except 3 will be printed.


121b. Consider the following code. What will be on the output. No Exception is thrown.

public class Mock3ExceptionTest{

public static void main(String [] args){

Mock3ExceptionTest e = new Mock3ExceptionTest();
e.trythis();
}

public void trythis(){

try{

System.out.println("1");
problem();
System.out.println("1b");
}

catch(Exception x){
System.out.println("3");

}

finally{
System.out.println("4");

}
System.out.println("5");
}


public void problem()throws Exception{

throw new Exception();
}
}

A. 1
B 1b
C. 3
D. 4
E. 5

ACDE.


122. What can you put where the X is?

X

Public class A{}

A. import java.awt.*;
B. package bla.bla;
C. class bla{}
D. public abstract final method();
E. public final int x = 1000;

ABC.


123. What are the characteristics of a totally encapsulated class? One answer.

A. methods not private
B. variables not public
C. ......
D. all modifying of the object should be made through methods

D.


124. Consider the following code:

public class TBMock1{

public static void main(String[]args){

Integer n = new Integer(7);
Integer k = new Integer(7);
Long i = new Long(7);
}
}

Which return true?

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


126. Consider the classes defined below:

import java.io.*;

class Super{

void method (int x, int b)
}

class Sub extends Super{}

How will a correct method in Sub look like?

A. int method(int x, int b)
B. void method (int x) throws Exception
C. void anotherMethod(int x)
D. ........

BC.


127. Consider the classes defined below:

import java.io.*;

class Super{

int method1 (int x, long b) throws IOException
{//code }
}

public class Sub extends 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.

A. public static void main (String args[]){}
B. float method2(){}
C. long method1 (int c, long d) {}
D. int method1(int c, long d) throws ArithmeticException{}
E. int method1 (int c, long d) throws FileNotFoundException{}

ABE.


128. What does the method getID do?

A. returns a value which shows the nature of the event
B. .......
C. ...
D. .....

A.


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. ...

BC. (not sure)


131 How can you declare a legal inner class?

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.


133. Claims about adapters and listeners


134. Which are legal identifiers

A. niceIdentifier
B. 2Goodbajs
C. %hejpådig
D. _goddag
E. Hello2

ADE.


135. 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 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.


137. Consider the following code:

String s = "Svenne";
int i = 1;

What can you do?

A String t = s>>i;
B Long x = 12;
String s = s + x;
C. .....
D. ......

B.


138. Assume that val has been defined as an int for the code below.

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

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

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

AB.


139. You are going to read some rows one by one from a file that is stored locally on your hard drive. How do you do it?

A. BufferedReader
B. InputStreamReader
C. One reader with "8859-1" as an argument
D. Don’t remember
E. FileReader

E. (Don’t remember if E was an alternative.)


140. What is a correct argument list for a public static void main method?

A. (String argv [])
B. (String arg )
C. (String [] fish)
D. (String args)
E. (String args{})

Made up alternatives C-E by myself.

AC.


141. Consider the following code:

What will be printed?

public class AB{

public static void main (String[] args){

int x = 1;

if (0 < x--){

System.out.println(x);
}
}

A. 0
B. 1
C. 2
D. Nothing
E. An IllegalArgumentException will be thrown

A.


141b. Consider the following code:

What will be printed?

public class AB{

public static void main (String[] args){

int x = 1;

if (0 < x--){

System.out.println(x);
}
}

A. 0
B. 1
C. 2
D. Nothing
E. An IllegalArgumentException will be thrown

D.


142. Which of the following are valid definitions of an application’s main ( ) method?

A. public static void main( );
B. public static void main( String args );
C. public static void main( String args [] );
D. public static void main( Graphics g );
E. public static boolean main( String args [] );

C.


143. Which of the following are Java keywords?

A array
B boolean
C Integer
D protect
E super

BE.


144. After the declaration:

char[] c = new char[100];

what is the value of c[50]?

A. 50
B. 49
C. ‘\u0000’
D. ‘\u0020’
E. ””
F. cannot be determined
G. always null until a value is assigned

C.


145. Which identifiers are valid?

A. _xpoints
B. U2
C. blabla$
D set-flow
E. something

ABCE.


146. Represent the number 6 as a hexadecimal literal.

Answer:

0x6, 0x06, 0X6, 0X06


147. Which of the following statements assigns "Hello Java" to the String variable s?

A. String s = ”Hello Java”;
B. String s [] = ”Hello Java”;
C. new String s = ”Hello Java”;
D. String s = new String ("Hello Java”);

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.


149. The statement ...

String s = "Hello" + "Java";

yields the same value for s as ...

String s = "Hello";
String s2 = "Java";
s.concat( s2 );

A. True
B. False

A.


150. If you compile and execute an application with the following code in its main()method:

String s = new String("Computer");

if ( s == "Computer" )
System.out.println ("Equal A”);
if( s.equals( "Computer" ) )
System.out.println ("Equal B”);

A. 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.


151. Given the variable declarations below:

byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;

Which one of the following assignments would need an explicit cast?

A. myInt = myByte;
B. myInt = myLong;
C. myByte = 3;
D. myInt = myChar;
E. myFloat = myDouble;
F. myFloat = 3;
G. my Double = 3.0;

BE.


152. Consider this class example:

class MyPoint {
void myMethod(){
int x, y;
x = 5; y = 3;
System.out.print("(” + x + ”, ” + y + ”)”);
switchCoords(x,y);
System.out.print("(” + x + ”, ” + y + ”)”);
}

void switchCoords(int x,int y){
int temp;
temp = x;
x = y;
y = temp;
System.out.print("(" + x + ", ” + y + ")”);
}
}

What is printed to standard output if myMethod() is executed?

A. (5, 3) (5, 3) (5, 3)
B. (5, 3) (3, 5) (3, 5)
C. (5, 3) (3, 5) (5, 3)

C.


153. To declare an array of 31 floating point numbers representing snowfall for each day of March in Gnome, Alaska, which declarations would be valid?

A. double snow[] = new double[31];
B. double snow[31] = new array[31];
C. double snow[31] = new array;
D. double[] snow = new double[31];

AD.


154. If arr[] contains only positive integer values, what does this function do?

public int guessWhat(int arr[]){
int x = 0;
for(int i = 0; i < arr.length; i++)
x = x < arr[i] ? arr[i] : x;
return x;
}

A. Returns the index of the highest element in the array
B. Returns true/false if there are any elements that repeat in the array
C. Returns how many even numbers are in the array
D. Returns the highest element in the array
E. Returns the number of question marks in the array

D.


155. Consider the code below:

arr[0] = new int[4];
arr[1] = new int[3];
arr[2] = new int[2];
arr[3] = new int[l];
for(int n = 0; n < 4; n++)
System.out.println ( /*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.


156. Which of the following are legal declarations of a two-dimensional array of integers?

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

C.


157. Given the variables defined below:

int one = 1;
int two = 2;
char initial = '2';
boolean flag = true;

Which of the following are valid?
A. if ( one ){}
B. if( one = two ){}
C. if( one == two ) {}
D. if( flag ){}
E. switch ( one ) { }
F. switch ( flag ) { }
G. switch ( initial ) { }

CDEG.


158. If val = 1 in the code below:

switch (val){
case 1: System.out.println(”P”);
case 2:
case 3: System.out.println("Q") ;
break;
case 4: System.out.println("R");
default: System.out.println ("S");
}

A. P
B. Q
C. R
D. S

AB.


159. What exception might a wait() method throw?

Answer:

InterruptedException


160. For the code:

m = 0;
while( m++ < 2 )
System.out.println(m);

Which of the following are printed to standard output?

A. 0
B. 1
C. 2
D. 3
E. Nothing and an exception is thrown

BC.


161. For the code:

m = 0;
while( ++m < 2 )
System.out.println(m);

Which of the following are printed to standard output?

A. 0
B. 1
C. 2
D. 3
E. Nothing and an exception is thrown

B.


162. Consider the following code sample:

class Tree{}
class Pine extends Tree{}
class Oak extends Tree{}
public class Forest {
public static void main (String [] args){
Tree tree = new Pine():

if( tree instanceof Pine )
System.out.println ("Pine");

if( tree instanceof Tree )
System.out.println ("Tree");

if( tree instanceof Oak )
System.out.println ( "Oak" );

else
System.out.println ("Oops ");
}
}

Select all choices that will be printed:

A. Pine
B. Tree
C. Forest
D. Oops
E. Nothing will be printed

ABD.


163. Which of the following statements about Java’s garbage collection are true?

A. The garbage collector can be invoked explicitly using a Runtime object.
B. The finalize method is always called before an object is garbage collected.
C. Any class that includes a finalize method should invoke its superclass’ finalize method.
D. Garbage collection behaviour is very predictable.

ABC.


164. What line of code would begin execution of a thread named myThread?

Answer:

myThread.start();


165. Which methods are required to implement the interface Runnable?

A. wait()
B. run()
C. stop()
D. update()
E. resume()

B.


166. What class defines the wait() method?

Answer:

Object.

for yield(), sleep(#), start(), run() it is Thread
for wait(), notify(), notifyAll() it is Object


167. For what reasons might a thread stop execution?

A. A thread with higher priority began execution.
B. The thread’s wait() method was invoked.
C. The thread invoked its yield() method.
D. The thread’s pause() method was invoked.
E. The thread’s sleep() method was invoked.

ABCE.


168. Which method below can change a String object, s ?

A. equals( s )
B. substring( s )
C. concat( s )
D. toUpperCase ( s )
E. none of the above will change s

E.


169. If s1 is declared as:

String sl = "phenobarbital";

What will be the value of s2 after the following line of code:

String s2 = s1.substring( 3, 5 );

A. null
B. "eno"
C. "enoba"
D. ”no”

D.


170. 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()
C. trunc()
D. abs()
E. floor()
F. ceil()

AF.


171. Which methods does java.lang.Math include for trigonometric computations?

A. sin( )
B. cos( )
C. tan ( )
D. aSin ( )
E. Cos ( )
F. aTan( )
G. toDegree ( )

ABC.


172. This piece of code:

TextArea ta = new TextArea ( 10, 3 );

Produces (select all correct statements):

A. a TextArea with 10 rows and up to 3 columns
B. a TextArea with a variable number of columns not less than 10 and 3 rows
C. a TextArea that may not contain more than 30 characters
D. a TextArea that can be edited

AD.


173. In the list below, which subclass(es) of Component cannot be directly instantiated:

A. Panel
B. Dialog
C. Container
D. Frame

C.


174. Of the five Component methods listed below, only one is also a method of the class MenuItem. Which one?

A. setVisible (boolean b)
B. setEnabled (boolean b)
C. getSize ()
D. setForeground (Color c)
E. setBackground (Color c)

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:

A. determined by the number of characters in the string, multiplied by the width of a character in this font
B. determined by the number of characters in the string, multiplied by the average width of a character in this font
C. exclusively determined by the number of characters in the string
D. undetermined

B.


176. 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:

A. BorderLayout in the North or South location
B. FlowLayout as the first component
C. BorderLayout in the East or West location
D. BorderLayout in the Center location
E. GridLayout

C.


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.

A. A class can implement multiple listener interfaces
B. If a class implements a listener interface, it only has to overload the methods it uses
C. All of the MouseMotionAdapter class methods have a void return type

AC.


184. Which of the following describe the sequence of method calls that result in a component being redrawn?

A. invoke paint() directly
B. invoke update which calls paint()
C. invoke repaint() which
D. invoke repaint() which invokes paint() directly

C.


185. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:

A. FileOutputStream(FileDescriptor fd)
B. FileOutputStream(String n, boolean b)
C. FileOutputStream(boolean a)
D. FileOutputStream()
E. FileOutputStream(File f)

ABE.


186. A "mode” argument such as "r" or ”rw” is required in the constructor for the class(es):

A. DataInputStream
B. InputStream
C. RandomAccessFile
D. File
E. None of the above

C.


187. A directory can be created using a method from the class(es):

A. File
B. DataOutput
C. Directory
D. FileDescriptor
E. FileOutputStream

A.


188. If raf is a RandomAccessFile, what is the result of compiling and executing the following code?

raf.seek(raf.length());

A. The code will not compile.
B. An IOException will be thrown.
C. The file pointer will be positioned immediately before the last character of the file.
D. The file pointer will be positioned immediately after the last character of the file.

D.


189. Consider the following code: What will be printed?

public class ExceptionTest{

public static void main(String [] args){

ExceptionTest e = new ExceptionTest();
e.trythis();
}

public void trythis(){

try{

System.out.println("1");
problem();
}

catch (RuntimeException x){

System.out.println("2");
return;
}

catch(Exception x){
System.out.println("3");
return;
}

finally{
System.out.println("4");
}
System.out.println("5");
}


public void problem()throws Exception{

throw new Exception();
}
}

1
2
3
4
5

ACD.


190. Consider the following code: What will be printed?


public class ExceptionTest2{

public static void main(String[] args){

ExceptionTest2 e = new ExceptionTest2();
e.divide(4, 0);}

public void divide(int a, int b){

try{
int c = a/b;
}
catch(ArithmeticException e){

System.out.println("ArithmeticException");
}

catch(RuntimeException e){

System.out.println("RuntimeException");
}

catch(Exception e){

System.out.println("Exception");
}


finally{

System.out.println("Finally");
}
}
}

ArithmeticException
RuntimeException
Exception
Finally

A. ArithmeticException D. Finally.


191. Consider the following code: What will be printed?


public class ExceptionTestMindQ{

public static void main(String [] args){

ExceptionTestMindQ e = new ExceptionTestMindQ();
e.trythis();
}

public void trythis(){

try{

System.out.println("Innan testet");
problem();
}

catch (NullPointerException x){

System.out.println("Nullpointer");

}

catch(Exception x){
System.out.println("Exception");
return;
}

finally{
System.out.println("finally");
}
System.out.println("mymethod is done");
}


public void problem()throws IllegalArgumentException{

throw new IllegalArgumentException();
}
}

Innan testet
Nullpointer´
Exception
finally
mymethod is done

A. Innan testet C. exception D. finally.


192. Consider the following code: What will be printed?

public class exceptiontest101{

public static void main(String[]args){

exceptiontest101 e = new exceptiontest101();
e.myMethod();
}
void myMethod(){
try{
fragile() ;
}
catch(NullPointerException npex){

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

public void fragile() {
throw new IllegalArgumentException();
}
}

NullpointerException thrown
Exception thrown
Done with exceptions
D.myMethod is done

B. Exception thrown C. Done with exceptions D. myMethod is done


193. What is the range of a short?

A. –128 – 127
B. -32 768 – 32 767
C. -231 – 231 -1
D. -263 – 263 -1

B.


194. What is the range of a short?

-128 – 127
-231 – 231 –1
C. -215 – 215 -1
D. -263 – 263 -1

B.


195. What is the range of a long?

-128 – 127
-231 – 231 –1
C. -215 – 215 -1
D. -263 – 263 -1

D.


196. Consider the following code: What will be printed?

public class Access{

int i = 10;
int j;
char z = 823;
char q = '1';
boolean b;
static int k = 9;

public static void main(String arg[]){

Access a = new Access();
a.amethod();
System.out.println(k);
}

public void amethod(){

System.out.println(j);
System.out.println(b);
System.out.println(z);
System.out.println(q);
}

}

0 true 823 1 9
null false 823 1 9
false 823 1 9 0
0 false ? 1 9
true 823 1 9 0

D.


197. Consider the following code: What will be printed?

public class amethod{

public static void main(String arg[]){

String s = "Hello";
char c ='H';
s+=c;
System.out.println(s);

}


}


A. Nothing will be printed because of a compilation error.
B. HelloH
C. Hhello
D. Hello\u345
Hello

B.


198. Consider the following code: What will be printed?

public class Arg{

String [] MyArg;


public static void main(String arg[]){

MyArg[] = arg[];
}

public void amethod(){

System.out.println(arg[1]);

}

}

null
0
Nothing will be printed. Compilation error.
Compiles just fine, but a RuntimeException will be thrown.

C.


199. Consider the following code: What will be printed?

public class Arg2{

static String [] MyArg = new String[2];


public static void main(String arg2[]){

arg2 = MyArg;

System.out.println(arg2[1]);

}

}

null
0
Nothing will be printed. Compilation error.
Compiles just fine, but a RuntimeException will be thrown.

A.


200. Consider the following code: What will be printed?

public class Arraytest{

public static void main(String kyckling[]){

Arraytest a = new Arraytest();
int i[] = new int[5];
System.out.println(i[4]);
a.amethod();
Object o[] = new Object[5];
System.out.println(o[2]);

}

void amethod(){
int K[] = new int[4];
System.out.println(K[3]);



}
}

A. null null null
B. null 0 0
C. 0 0 null
D. 0 null 0

C.


201. Consider the following code: What will be printed?

class Arraytest2{


public static void main(String[]args){

int [] arr = {1, 2, 3};

for(int i = 0; i < 2; i++){

arr[i] = 0;
}

for(int i = 0; i < 3; i++){
System.out.println(arr [i]);
}
}
}

1 2 3
0 0 3
0 2 3
0 0 0

B.


202. Consider the following code: What will be printed?

public class ArrayTest3{

public static void main(String[]args){

int [][] a = new int[5][5];
System.out.println(a[4][4]);
}
}

0 0 0 0
0 0
0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

C.


203. Consider the following code: What will be printed?

public class booleanFlag{

public static void main(String[] args){
test();
test2();
}

public static void test(){

//boolean flag = false;

if(flag=true){

System.out.println("true");

}

else {

System.out.println("false");
}}

public static void test2(){
boolean flag = false;
if(flag==true){

System.out.println("true");
}

else {
System.out.println("false");
}
}
}

true true
true false
false true
false false
Compilation error. Cannot resolve symbol: variable flag.

E.


204. Consider the following code: What will be printed?

class CeilTest{



static float k = 3.2f;


public static void main(String[]args){


System.out.println("Ceil for 3.2 is: " + Math.ceil(k) + "Floor for 3.2 is: " + Math.floor(k));

}
}

Ceil for 3.2 is : 4.0 Floor for 3.2 is : 3.0
Ceil for 3.2 is : 3.0 Floor for 3.2 is : 4.0
Ceil for 3.2 is : 4 Floor for 3.2 is : 3
Ceil for 3.2 is : 3 Floor for 3.2 is : 4
Compiler error. Variable k cannot be reached.

A.


205. Consider the following code: What will be printed?

public class DoubleTest{

public static void main(String[]args){



Float i = new Float(0.9f);
Float j = new Float(0.9f);

if(i.equals(j))
System.out.println("i.equals(j)");
if(i==j)
System.out.println("i==j");

float s = 10.0f;
int t = 10;
long x = 10;
char u = 10;

if(s==t)
System.out.println("s==t");
if(x==u)
System.out.println("x==u");

}}

i.equals(j) i==j s==t x==u
B. i==j s==t x==u
C. i.equals(j) s==t x==u
i.equals(j) x==u

C. What makes the difference here is the new operator. You get fooled and think that s = = t and x = = u would return false.


206. Consider the following code: What will be printed?

public class Equal{

public static void main(String kyckling[]){

int Output = 10;

boolean b1 = false;

if((b1==true) && ((Output+=10)==20))
{
System.out.println("We are equal " + Output);
}
else
{System.out.println("Not equal! " + Output);
}
}}

A. Nothing will be printed. You must use the word args instead of kyckling in the main method.
We are equal 10
Not equal 10
We are equal 20
Not equal 20

C.


207. Consider the following code: What will be printed?

public class EqualsTest{

public static void main(String[]args){


if ("john" == "john")
System.out.println("\"john\" == \"john\"");

if("john".equals("john"));
System.out.println("\"john\".equals(\"john\")");

Boolean flag = new Boolean(true);
boolean flagga = true;


}
}

john == john
“john” == “john” “john”.equals “john”
john == john john.equals john
john.equals john
“john” == “john”
“john”.equals “john”

B.


208. Consider the following code: What will be printed?

public class EqualsTest2{

public static void main(String[]args){
byte A = (byte)4096;

if (A == 4096)
System.out.println("Equal");

else System.out.println("Not Equal");

System.out.println(A);

int B = (int)4096;

if (B == 4096)
System.out.println("Equal");

else System.out.println("Not Equal");

System.out.println(A);

}

}

Not Equal Not Equal 0
Not Equal Equal 0
Equal Not Equal 4096
Equal Equal 4096

B.

A byte can store values from –128-127. Therefore the variable A will not be able to store 4096.


209. Consider the following code: What will be printed?

class ExampleInteger extends Object{

public static void main(String[] args){

ExampleInteger e = new ExampleInteger();
e.Result(30);
}

public void Increment(Integer N){
N = new Integer(N.intValue() + 1);
}

public void Result(int x){

Integer X = new Integer(x);
Increment(X);
System.out.println("New value is " + X);
}
}

New value is 30
New value is 31
New value is 1
New value is null

A.


210. Consider the following code: What will be printed?

public class Hope{

public static void main(String[]args)
{
Hope h = new Hope();
}

protected Hope(){

for(int i = 0; i < 10; i++){

System.out.println(i);}

}}

0 1 2 3 4 5 6 7 8 9
Compiler error. Constructor cannot be protected.
1 2 3 4 5 6 7 8 9 10


211. Consider the following code: What will be printed?

public class Init{



public static void main(String arg[]){

int[]a = new int[5];
String s[] = new String[5];


for (int i = 0; i System.out.println(a[1]);
}
System.out.println(s[3]);


}

}

0 null 0 null 0 null 0 null 0 null
0 0 0 0 0 null null null null null
0 null
0 0 0 0 0 null
Nothing will be printed due to Compilation Error.

D.


212. Consider the following code: What will be printed?


public class Init2{



public static void main(String arg[]){

int[]a = new int[5];
String s[] = new String[5];
String t[];
String u;


System.out.println(a[1]);
System.out.println(s[3]);

System.out.println(t[3]);
System.out.println(u);
}

}


0 null null null
0 0 0 0 null null null null
null null null null
null 0 0 0
Nothing will be printed: Variable t and u may not have been initialized.

E.


213. Consider the following code: What will happen when you try to compile it?

public class InnerClass{

public static void main(String[]args)
{}


public class MyInner{


}}

It will compile fine.
It will not compile, because you cannot have a public inner class.
It will compile fine, but you cannot add any methods, because then it will fail to compile.

A.


214. Consider the following code: What will be printed?

public class charTest2{

public static void main(String[] args){


int y = 020;
char b = '\u0010';

if(b==y)
System.out.println("Char 'u0010' = 16.0");
}
}

A. Nothing will be printed.
B. Compilation error. The char variable cannot be assigned this way.
C. Char 'u0010' = 16.0
Compilation error. The int variable cannot be assigned this way.
Compilation error. The char variable cannot be assigned this way. The int variable cannot be assigned this way.

C.


215. If you’re stupid and program like this. What will happen?

public class LoseInformationCast2{

public static void main(String[]args){

byte b = (byte)259;
short s = (short)b;

System.out.println("short s =" + s + " byte b = " + b);


}
}

short s = 3 + byte b = 3
short s = 3 byte b = 3
short s = 3 byte b = 259
Nothing will be printed. Illegal explicit cast.

B.


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);

}
}


short s = 259 + byte b = 3
short s = 259 = byte b = 3
short s = 3 byte b = 259
Nothing will be printed. Illegal explicit cast.

B.


217. Consider the following code: What will be printed?

public class maze{

public static void main(String[]args){

int x = 4;

if(x<=7){

if(x==5)
System.out.println("2");
System.out.println("1");
}

else if (x==17)
System.out.println("3");

else if (x==18)
System.out.println("4");
System.out.println("0");

}

}

Nothing will be printed.
0
1 0
Compilation Error. You can not use two else if statements in this way.
2 1 3 4 0

C.


218. Consider the following code: What will be printed?

public class maze2{

public static void main(String[]args){

int x= 4;

if(x<=7){

if(x==5){
System.out.println("2");
System.out.println("1");
}
}

else if (x==17)
System.out.println("3");

else if (x==18){
System.out.println("4");
System.out.println("0");
}

}

}


Nothing will be printed.
0
1 0
Compilation Error. You can not use two else if statements in this way.
2 1 3 4 0

A.


219. Consider the following code: What will be printed?

public class maze3{

public static void main(String[]args){

int x= 4;

if(x<=7){

if(x==5){
System.out.println("2");
System.out.println("1");
}
}

else if (x==17)
System.out.println("3");

else if (x==18){
System.out.println("4");
}
System.out.println("0");


}

}


Nothing will be printed.
0
1 0
Compilation Error. You can not use two else if statements in this way.
2 1 3 4 0

B.


220. Consider the following code: What will be printed?

public class MyAr{

public static void main(String args[]){


MyAr m = new MyAr();
m.amethod();
}

public void amethod(){

int i = 12;

System.out.println(i);
}
}

12
null
Error you cannot initialize a non-static variable in the main method.
0

A.


221. Consider the following code: What will be printed?

public class MyAr{

public static void main(String args[]){


MyAr m = new MyAr();
m.amethod();
}

public void amethod(){

static int i; System.out.println(i);
}
}

A. 1
null
Syntax error: illegal start of expression. You cannot define an integer as static inside a non-static method
0
Syntax error: illegal start of expression. Error you cannot define an integer as non-static inside a static method.

C.


222. Consider the following code: What will be printed?

public class MyAr{

public static void main(String args[]){


MyAr m = new MyAr();
m.amethod();
}

public void amethod(){

int i;
System.out.println(i);
}
}

A. 1
null
Error. Variable i might not have been initialized.
0
Error you cannot define an integer as non-static inside a static method.

C.


223. Consider the following code: What will be printed?

public class newIntegerLong{


public static void main(String[]args){

Integer nA = new Integer(4096);
Long nB = new Long(4096);

if(nA.equals(nB))
System.out.println("LongEqualsInteger.");

if(nA.intValue() == nB.longValue()){
System.out.println("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.
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.


224. Consider the following code: What will be printed?

public class Q{

public static void main(String arg[]){

int anar[] = new int[]{1,2,3};
System.out.println(anar[1]);

int i = 9;

switch(i){

default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
boolean b=true;
boolean b2 = true;
if (b==b2){
System.out.println("So true");

}
}
}


2 default so true
2 default zero so true
1 default zero so true
0 default so true
2 default zero two
2 default zero two so true

B.


225. Consider the following code: What will be printed?

public class Scope{

private int i;

public static void main(String arg[]){

Scope s = new Scope();
s.amethod();
}

public static void amethod(){
System.out.println(i);
}

}

0
null
Error. Non-static variable i cannot be referenced from a static context.
Error. Variable I may not have been initialized.

C.


Consider the following code: What will be printed?

public class StringBuf{

public static void main(String args[]){

StringBuffer sb = new StringBuffer("abc ");
String s = new String(" a b c");
String st = "ABCDE";

sb.append("def ");//nu är s = abc def
sb.insert(1, " zzz ");//nu är s = a zzz bc def
String i = s.concat(st);
s = s.trim();



System.out.println(s);
System.out.println(sb);
System.out.println(st.indexOf("C"));
System.out.println(st.indexOf('A'));
System.out.println(st.indexOf('A', 2));
System.out.println(st.indexOf('G'));
System.out.println(i);
}
}

What will be printed?


abc
azzz bc def
2
0
-1
-1
a b cABCDE


a b c
abc def zzz
2
0
-1
-1
a b c ABCDE

C.
abc
abcdefzzz
2
0
1
-1
a b c ABCDE

D.
a b c
a zzz bc def
2
0
-1
-1
a b cABCDE

D.

227. Consider the following code: What will be printed?

public class StringBufferTest{

public static void main(String[]args){

StringBuffer sb1 = new StringBuffer("Anna");
StringBuffer sb2 = new StringBuffer("Anna");

if (sb1.equals(sb2))

System.out.println("Equals");

else

System.out.println("StringBuffer Equals not");

String s1 = new String("Anna");
String s2 = new String("Anna");

if (s1.equals(s2))

System.out.println("String Equals");

else

System.out.println("Equals not");
}
}


Equals
Equals not

StringBuffer Equals not
String Equals

Equals
String Equals
D.
StringBuffer Equals not
Equals not

B.

228. Consider the following code: What will be printed?

public class StringBufferTest2{



public static void main(String[]args){


String a, b;
StringBuffer c, d;

c = new StringBuffer("Kalle");
a = new String("Kalle");
b = a;
d = c;
StringBuffer e = new StringBuffer("Kalle");
String f = new String("Kalle");

if(b.equals(a))
System.out.println("b.equals(a)");

if(b==a)
System.out.println("b==a");

if(d.equals(c))
System.out.println("d.equals(c)");

if(d==c)
System.out.println("d==c");

if(f.equals(a))
System.out.println("f.equals(a)");

if(f==a)
System.out.println("f==a");
else
System.out.println("f!=a");

if(e.equals(c))
System.out.println("e.equals(c)");
else
System.out.println("e.equalsnot(c)");

if(e==c)
System.out.println("e==c");
else
System.out.println("e!=c");

}
}

A.
b.equals(a)
b==a
d.equals(c)
d==c
f.equals(a)
f!=a
e.equalsnot(c)
e!=c

B.
b.equals(a)
b==a
d.equals(c)
d==c
f!=a
e.equalsnot(c)
e!=c

C.
b.equals(a)
d.equals(c)
f.equals(a)
f==a
e.equals(c)
e!=c

D.
b==a
d==c
f.equals(a)
f!=a
e.equalsnot(c)
e==c

E.
b.equals(a)
b==a
d.equals(c)
d==c
f.equals(a)
e.equals(c)
e!=c

A.

229. Consider the following code: What will be printed?

public class StringTest{

public static void main(String[] args){

String s = "Kalle och Matte";

int i = s.length();
int j = args.length;

System.out.println(i + " " + j);
}}

13 13
13 0
15 0
15 13
15 null
15 + + 0
13 + + 0

C.

230. Check and run this code and you will see how the round method in the Java.lang.math class will behave when you have –4.5 and 4.5. 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);

int o = (int)Math.floor(-4.4);
System.out.println("Math.floor(-4.4) = " + o);

int p = (int)Math.floor(4.4);
System.out.println("Math.floor(4.4) = " + p);

int q = (int)Math.floor(4.5);
System.out.println("Math.floor(4.5) = " + q);
}
}

231. Consider the following code: What will be printed?

public class Testa
{

Integer a = 10;
Integer b = 20;
Integer c = 10;

public static void main (String[] args){

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.


Consider the following code: What will be printed?

public class Testb
{

static Integer a = 10;
static Integer b = 20;
static Integer c = 10;

public static void main (String[] args){

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.

F.


232. Consider the following code: What will be printed?

public class Testc
{

static Integer a = new Integer(10);
static Integer b;
static Integer c = new Integer(10);

public static void main (String[] args){

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.


233. Consider the following code: What will be printed?

class Unchecked{

public static void main(String[]args){

try{
method();
}
catch (Exception e) {
System.out.println("Fångar Exception");
}
}

static void method(){

try{
method1();

System.out.println("Testar method1");
}

catch (ArithmeticException ae) {

System.out.println("Fångar ArithmeticException");
}

finally{

System.out.println("Kör finally");
}
System.out.println("I method() utanför finally");
}

static void wrench(){

throw new NullPointerException();
}
}

A. Kör finally. I method() utanför finally. Fångar Exception.
Kör finally. Fångar Exception.
None.
Kör finally.

B.


234. Consider the following code: What will be printed?

class Unchecked1{

public static void main(String[]args){

}
void method(){

try{
metod1();

System.out.println("Testar metod1");
}

catch (ArithmeticException ae) {

System.out.println("Fångar ArithmeticException");
}

finally{

System.out.println("Kör finally");
}
System.out.println("I method() utanför finally");
}

void metod1(){

throw new NullPointerException();
}
}


Kör finally. I method() utanför finally. Fångar Exception.
Kör finally. Fångar Exception.
None.
Kör finally.

C. (Strange but that´s it).



mail the dump to newcheckpoint@sasaschool.com orsubmit dump online(prefer)

back to home

CHECKPOINT MCSE
Originally created by Thomas Leuthard.
Updated by Sasa.
Kept alive by you.


Click here to download your free 5-user version! 1