Question 61:   |
|
From: Thomas Bengtsson (24 Feb 2000) / 1.x | |
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.
|
while (args[count] != null) count ++; | |
D.
|
int count = 0; while (!(args[count].equals(""))) count ++; |
Question 62:   |
|
From: Thomas Bengtsson (24 Feb 2000) / 1.x | |
Which are keywords in Java? |
A.
|
sizeof | |
B.
|
abstract | |
C.
|
native | |
D.
|
NULL | |
E.
|
BOOLEAN |
Question 63:   |
|
From: Thomas Bengtsson (24 Feb 2000) / 1.x | |
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; } } |
Question 64:   |
|
From: Thomas Bengtsson (24 Feb 2000) / 1.x | |
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; } } |
Question 65:   |
|
From: Thomas Bengtsson (24 Feb 2000) / 1.x | |
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 |
Question 66:   |
|
From: Thomas Bengtsson (24 Feb 2000) / 1.x | |
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); |
Question 67:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.x | |
Which cannot be added to a Container? |
A.
|
a Menu | |
B.
|
a Panel | |
C.
|
an Applet | |
D.
|
a Component | |
E.
|
a Container |
Question 68:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.x | |
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 |
Question 69:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.x | |
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 |
Question 70:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.x | |
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 |
Question 71:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.x | |
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. |
Question 72:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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? |
Question 73:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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? |
Question 74:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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]; |
Question 75:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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() |
Question 76:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 77:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 78:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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 |
Question 79:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 80:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 81:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 82:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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.
|
Legal at compile time, but may fail at runtime. | |
E.
|
Legal at both compile and runtime. |
Question 83:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 84:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 85:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.1.x | |
What would you use when you have duplicated values that needs to be sorted? |
A.
|
Map | |
B.
|
Set | |
C.
|
Collection | |
D.
|
List | |
E.
|
Enumeration |
Question 86:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.1.x | |
What kind of reader do you use to handle ASCII code? |
A.
|
BufferedReader | |
B.
|
ByteArrayReader | |
C.
|
PrintWriter | |
D.
|
InputStreamReader | |
E.
|
FilterReader |
Question 87:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 88:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
What is the return-type of the methods that implement the MouseListener interface? |
A.
|
boolean | |
B.
|
Boolean | |
C.
|
void | |
D.
|
Point |
Question 89:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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. |
Question 90:   |
|
From: Thomas Bengtsson (12 Feb 2000) / 1.0.2 | |
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"); } |
{loading}{scripting-1}{scripting}
The Notes
More is added to the list, but what I realy need is your help to keep
this information up-to-date and may be it needs correcting in one way
or the other. Please feel free to help me complement these question
and answers drop us an email at this
address. (C) 1998-2001, BMC88 - Personal WebSite of Java Certification
Exams
Part I
Part II
Part III
Part IV
Answers{submenus}