Java MockExam - 8
Java MockExam - 8
Java MockExam - 8
4)
JavaBeat Home SCJP 1.4 Home Objectives Forums Mock Exams Online Mock Exam Resources
Mock Exams
MockQuestions - 1 MockQuestions - 2 MockQuestions - 3 MockQuestions - 4
MockQuestions - 5 MockQuestions - 6 MockQuestions - 7 MockQuestions - 8
MockQuestions - 9 MockQuestions - 10 MockQuestions - 11 MockQuestions - 12
MockQuestions - 13 MockQuestions - 14 MockQuestions - 15 MockQuestions - 16
MockQuestions - 17 MockQuestions - 18 MockQuestions - 19 MockQuestions - 20
A) String str[];
B) String str[5] = new String[5];
C) String str[] = new String[] {"string1", "string2", "string3", "string4", "string5"};
D) String str[] = {"string1","string2", "string3", "string4", "string5"};
A) final
B) Abstract
C) Long
D) static
A) Class declarations.
B) Method declarations.
C) Block of code declarations
D) Variable declarations.
class A {
A() {
System.out.println("Class A Constructor");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}
5. Given the piece of code, select the correct to replace at the comment line?
class A {
A(int i) { }
}
public class B extends A {
B() {
// xxxxx
}
public static void main(String args[]) {
B b = new B();
}
}
A) super(100);
B) this(100);
C) super();
D) this();
int i = 100;
switch (i) {
case 100:
System.out.println(i);
case 200:
System.out.println(i);
case 300:
System.out.println(i);
}
A) Nothing is printed
B) Compile time error
C) The values 100,100,100 printed
D) Only 100 is printed
8. How can you change the break statement below so that it breaks out of the inner and middle loops
and continues with the next iteration of the outer loop?
A) continue middle
B) break middle:
C) break outer:
D) continue
import java.io.*;
class MyExp {
void MyMethod() throws IOException, EOFException {
//............//
}
}
10. What is the result when you compile the and run the following code?
public class ThrowsDemo {
static void throwMethod() {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
A) Compilation error
B) Runtime error
C) Compile successfully, nothing is printed.
D) Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo
11. Which of the following statements about garbage collection are true?
12. From the following code how many objects are eligible for garbage collection?
A) 1
B) 2
C) 3
D) 0
A) superclass
B) goto
C) open
D) integer
E) import, package
F) They are all java keywords
16. Which of the following class definitions are legal declaration of an abstract class?
18. What is the result of compiling the following code? When you run like given below?
A) goto
B) synchronized
C) extends
D) implements
E) this
F) NULL
A) A null is printed
B) Compile time error
C) Exception is thrown
D) null followed by 0 is printed on the screen
A) long l = 698.65;
B) float f = 55.8;
C) double d = 0x45876;
D) All of the above
22. What is the numeric range for a Java int data type?
A) 0 to (2^32)
B) -(2^31) to (2^31)
C) -(2^31) to (2^31 - 1)
D) -(2^15) to (2^15 - 1)
-----------
A) int getID()
B) String getSource()
C) int returnID()
D) int eventID()
26. Which of the following are correct, if you compile the following code?
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
28. Given the byte with a value of 01110111, which of the following statements will produce
00111011?
A) 0x77 << 1;
B) 0x77 >>> 1;
C) 0x77 >> 1;
D) None of the above
A) char c = 'a';
B) double d = 45.6;
C) int i = d;
D) int k = 8;
30. Which of the following returns true when replace with XXXXXXXXX?
A) b instanceof Button
B) Button instanceof b
C) b == Button
D) Button == (Object) b
A) A equals a divided by 5;
B) A equals A in 5 digit percentage form
C) A equals A modulus 5.
D) None of the above
32. What will happen when you attempt to compile and run the following code?
33. What is the result when you try to compile and run the following code?
34. Given the following declaration which of the following statements equals to true
boolean b1 = true;
boolean b2 = false;
A) b1 == b2;
B) b1 || b2;
C) b1 |& b2;
D) b1 && b2;
37. Given the following class definition, which of the following methods could be legally placed after
the comment ?
//Here
}
class Base{
Derived(int i){
super(i);
this(i);
//Here
}
}
46. Which of the following statements are true about the fragment below?
import java.lang.Math;
49. Which of the following implement clear notion of one item follows another (order)?
A) List
B) Set
C) Map
D) Iterator
50. Collection interface iterator method returns Iterator(like Enumerator), through you can traverse
a collection from start to finish and safely remove elements.
A) true
B) false
51. Which of the following places no constraints on the type of elements, order of elements, or
repetition of elements with in the collection.?
A) List
B) Collection
C) Map
D) Set
A) Map
B) Collection
C) List
D) Set
53. If you run the following code on a PC from the directory c:\source:
import java.io.*;
class Path {
public static void main(String[] args) throws Exception {
File file = new File("Ran.test");
System.out.println(file.getAbsolutePath());
}
}
What do you expect the output to be? Select the one right answer.
A) Ran.test
B) source\Ran.test
C) c:\source\Ran.test
D) c:\source
E) null
55. You have an 8-bit file using the character set defined by ISO 8859-8. You are writing an
application to display this file in a TextArea. The local encoding is already set to 8859-8. How can
you write a chunk of code to read the first line from this file?
A)
B)
C)
D)
E)
56. Which of the following used to read and write to network sockets, which are super classes of
Low level streams?
A) InputStream
B) StreamReaders
C) OutputStream
D) Writers
E) Readers
F) Streams
57. Low Level Streams read input as bytes and writes as bytes, then select the correct declarations
of Streams.
58. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:
A) FileOutputStream( FileDescriptor fd )
B) FileOutputStream( String n, boolean a )
C) FileOutputStream( boolean a )
D) FileOutputStream()
E) FileOutputStream( File f )
59. What is the class that has "mode" argument such as "r" or "rw" is required in the constructor:
A) DataInputStream
B) InputStream
C) RandomAccessFile
D) File
60. What is the output displayed by the following code?
import java.io.*;
A) 123456
B) 7890
C) 1000000
D) .0001
Answers
Answer 1:
A) String str[];
C) String str[] = new String[] {"string1", "string2", "string3", "string4", "string5"};
D) String str[] = {"string1","string2", "string3", "string4", "string5"};
Answer 2:
A) final
D) static
Answer 3:
B) Method declarations.
C) Block of code declarations
Answer 4:
A) super(100);
Answer 6:
Answer 7:
Answer 8:
B) break middle;
Answer 9:
Answer 10:
A) Compilation error
Answer 11:
Answer 12:
A) 1
Answer 13:
B) goto
E) import, package
NOTE: The keywords 'const' and 'goto' are reserved by Java, even though they are not currently used in Java.
For more information at http://java.sun.com/docs/books/jls/html/3.doc.html#229308
Answer 14:
B) new Inner() { }
Answer 15:
Answer 17:
Answer 18:
Answer 19:
A) goto
B) synchronized
C) extends
D) implements
E) this
Answer 20:
C) Exception is thrown
Answer 21:
A) long l = 698.65;
B) float f = 55.8;
Answer 22:
C) -(2^31) to (2^31 - 1)
Answer 23:
Explanation:
The 7 can be represented any one of the above mentioned answers.
Answer 24:
0 to 2^16-1
Answer 25:
A) int getID()
Answer 26:
B) Java 1.0 and Java 1.1 event handling models are not compatible
C) Event listeners are the objects that implements listener interfaces.
D) You can add multiple listeners to any event source, then there is no guarantee that the listeners will be
notified in the order in which they were added.
Answer 28:
B) 0x77 >>> 1;
C) 0x77 >> 1;
Answer 29:
A) char c = 'a';
B) double d = 45.6;
D) int k = 8;
Answer 30:
A) b instanceof Button
Answer 31:
C) A equals A modulus 5.
Answer 32:
C) No output
Answer 33:
Answer 34:
B) b1 || b2;
Explanation:
A) This returns false. == is used as comparison operator.
B) This returns true. Because of OR operation.
C) There is no operator like that.
D) This returns false. This is because of AND operation.
NOTE: The operators ||, && are called short-circuit operators. The operator || ( OR Operation ) returns true if
one operand is true without regard to the other operand. The operator && ( AND Operation ) returns false if one
operand is false, without regard to the other operand . In our example b1 is true and b2 is false.
Answer 35:
Answer 37:
Answer 38:
Explanation:
A) This is wrong because there is no matching constructor defined in Derived class.
B) The super keyword suppose to be the first line in the constructor.
C) The this keyword suppose to be first line in the constructor.
D) This is correct because there is matching constructor in Base class.
Answer 39:
Answer 40:
Answer 41:
Answer 42:
Answer 43:
Answer 44:
Answer 45:
A) gridwidth, gridheight, specifies how many columns and rows to span.
B) gridx, gridy has GridBagConstraints.RELATIVE which adds left to right and top to bottom, still you can specify
gridwidth and gridheight except for last component, which you have to set GridBagConstraints.REMAINDER.
Answer 46:
Answer 47:
Answer 48:
Answer 49:
A) List
Answer 50:
A) true
Answer 51:
B) Collection
Answer 52:
C) List
Answer 53:
C) c:\source\Ran.test
Answer 54:
Answer 55:
A)
B)
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
E)
Answer 56:
A) InputStream
C) OutputStream
Answer 57:
Answer 58:
A) FileOutputStream( FileDescriptor fd )
B) FileOutputStream( String n, boolean a )
E) FileOutputStream( File f )
Answer 59:
C) RandomAccessFile
Answer 60:
B) 7890