It covers File, FileReader, FileWriter, BufferedReader, BufferedWriter, FileInputStream, FileOutputStream, PrintWriter, ObjectInputStream, ObjectOutputStream.
Questions 1-9 are about File, 10-26 for Input/Output and 27-50 specific to Serialization.
Here is a simple overview of some interesting classes in the java.io package. The arrows denote decoration.
- What happens when this code is compiled and executed? (1 correct answer)
String name = null; File file = new File(name); System.out.println(file.getName());
- It prints “null”.
- NullPointerException at second line.
- NullPointerException at third line.
- Compilation fails.
- What happens when this code is compiled and executed? (1 correct answer)
String name = null; File file = new File("/folder", name); System.out.print(file.exists());- It prints “true”.
- It prints “false”.
- NullPointerException at second line.
- NullPointerException at third line.
- What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { String parent = null; File file = new File(parent, "myfile.txt"); file.createNewFile(); }- An empty file myfile.txt is created at the current directory.
- An empty file myfile.txt is created at the root directory.
- NullPointerException at second line.
- NullPointerException at third line.
-
This program is executed in Windows. In Windows systems root is C:\ and the separator char is \.
File file = new File("/file.txt");What is the output of the following statements?
- System.out.println(“path → ” + file.getPath());
- System.out.println(“absolute → ”
+ file.getAbsolutePath()); - System.out.println(“canonical → ”
+ file.getCanonicalPath());
-
This program is executed in folder C:\documents of Windows. In Windows systems root is C:\ and the separator char is \.
File file = new File("file.txt");What is the output of the following statements?
- System.out.println(“path → ” + file.getPath());
- System.out.println(“absolute → “
+ file.getAbsolutePath()); - System.out.println(“canonical → “
+ file.getCanonicalPath());
-
This program is executed in folder C:\parent\child of Windows. In Windows systems root is C:\ and the separator char is \.
File file = new File("../file.txt");What is the output of the following statements?
- System.out.println(“path → ” + file.getPath());
- System.out.println(“absolute → “
+ file.getAbsolutePath()); - System.out.println(“canonical → “
+ file.getCanonicalPath());
-
This program is executed in OpenSolaris. In Unix systems root is / and separator char is /.
File file = new File("/file.txt");What is the output of the following statements?
- System.out.println(“path → ” + file.getPath());
- System.out.println(“absolute → “
+ file.getAbsolutePath()); - System.out.println(“canonical → “
+ file.getCanonicalPath());
-
This program is executed in directory /usr/prog of OpenSolaris. In Unix systems root is / and separator char is /.
File file = new File("file.txt");What is the output of the following statements?
- System.out.println(“path → ” + file.getPath());
- System.out.println(“absolute → “
+ file.getAbsolutePath()); - System.out.println(“canonical → “
+ file.getCanonicalPath());
-
This program is executed in directory /test of OpenSolaris. In Unix systems root is / and separator char is /.
File file = new File("../file.txt");What is the output of the following statements?
- System.out.println(“path → ” + file.getPath());
- System.out.println(“absolute → “
+ file.getAbsolutePath()); - System.out.println(“canonical → “
+ file.getCanonicalPath());
-
Which class is used to read streams of characters from a file? (1 correct answer)
- FileReader
- FileWriter
- FileInputStream
- FileOutputStream
-
Which class is used to write streams of raw bytes to a file? (1 correct answer)
- FileReader
- FileWriter
- FileInputStream
- FileOutputStream
- What is the name of the abstract parent class of FilerWriter?
- What is the name of the abstract parent class of FileInputStream?
-
Is this a valid statement?
new BufferedWriter(new BufferedWriter( new BufferedWriter(new FileWriter("myfile.txt")))); - Consider an empty file C:/empty.txt. What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { BufferedReader reader = new BufferedReader( new FileReader("C:/empty.txt")); System.out.println(reader.getLine()); }- It prints an empty string “”.
- It prints null.
- A NullPointerException is thrown at runtime.
- Compilation fails.
- Consider an empty file C:/empty.txt. What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { BufferedReader reader = new BufferedReader( new FileReader("C:/empty.txt")); System.out.println(reader.readLine()); }- It prints an empty string “”.
- It prints null.
- A NullPointerException is thrown at runtime.
- Compilation fails.
- What happens when this code is compiled and executed? (1 correct answer)
void test() { FileWriter writer = new FileWriter("/fun.log"); writer.write("Hello!"); writer.close(); }- A file fun.log is created with the content “Hello!”.
- A file fun.log is created but it’s empty, because flush() was not called.
- A runtime exception is thrown because flush() was not called.
- Compilation fails.
- What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { FileWriter writer = new FileWriter("/fun.log"); writer.write("Hello!"); writer.close(); }- A file fun.log is created with the content “Hello!”.
- A file fun.log is created but it’s empty, because flush() was not called.
- A runtime exception is thrown because flush() was not called.
- Compilation fails.
- Consider a file fun.log whose first line is “Hello!”. What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { File file = new File("C:/fun.log"); BufferedReader reader = new BufferedReader(file); System.out.println(reader.readLine()); }- A runtime exception is thrown because the file already exists.
- It prints “Hello!”.
- It prints “null”.
- Compilation fails.
- What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { PrintWriter writer = new PrintWriter(new PrintWriter("yo.txt")); writer.print("yo"); writer.flush(); writer.close(); }- Compilation fails because a PrintWriter cannot accept a PrintWriter in its constructor.
- Compilation fails because there is no method print().
- Two files yo.txt with the same content are created.
- A file yo.txt with the content “yo” is created.
- What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { for (int index = 1; index <= 2; index++) { PrintWriter writer = new PrintWriter("/apa"); writer.print("apa"); writer.close(); } }- A file apa is created with content “apa”.
- A file apa is created with content “apaapa”.
- Two files are created.
- An exception is thrown at runtime.
- The file fun.log has already some content. We want to keep the content of the file and add a new line at the end. Which statement can achieve this? (1 correct answer)
void test() throws IOException { PrintWriter writer = new PrintWriter("C:/fun.log"); // insert statement here writer.flush(); writer.close(); }- writer.println(“this is a new line”);
- writer.append(“this a new line”);
- writer.append(“\nthis is a new line”);
- None of the above.
-
Is this a valid statement?
OutputStream out = new OutputStream(new File("directory", "file")); - Consider the file empty.txt really exists and is empty. What is the output of this method? (1 correct answer)
void test() throws IOException { FileInputStream input = new FileInputStream("/empty.txt"); int i = input.read(); input.close(); System.out.println(i); }- It prints 0.
- It prints -1.
- Compilation fails.
- An exception is thrown at runtime when the read() method is invoked.
- What happens when this code is compiled and executed? (1 correct answer)
void test() throws IOException { FileOutputStream out = new FileOutputStream("shakira.mp3"); out.write(1000); out.flush(); out.close(); }- Compilation fails because 1000 is not a byte.
- A runtime exception is thrown because 1000 is not a byte.
- A runtime exception is thrown because shakira.mp3 is a music file!
- The program compiles and runs fine.
- What is the output of this method? (1 correct answer)
void test() throws IOException { // write OutputStream out = new FileOutputStream("/my"); out.write(22); out.close(); // read InputStream input = new FileInputStream("/my"); System.out.println(input.read() + " " + input.read()); input.close(); }- 22 -1
- 22 0
- 22 null
- A runtime exception is thrown.
- What happens when this code is compiled and executed? (1 correct answer)
import java.io.*; public class Person { String name; int age; public Person(String name, int age) { this.age = age; this.name = name; } public String toString() { return "Hello it's " + name + "! I am " + age + " years old."; } public static void main(String[] args) throws ClassNotFoundException, IOException { Person before = new Person("Shakira", 30); ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/person")); out.writeObject(before); ObjectInputStream input = new ObjectInputStream( new FileInputStream("/person")); Person after = (Person)input.readObject(); System.out.println(after); } }- It prints “Hello it’s Shakira! I am 30 years old”.
- A ClassNotFoundException is thrown because Person does not implement Serializable.
- A NotSerializableException is thrown because Person does not implement Serializable.
- Compilation fails because NotSerializableException is not handled properly.
- Compilation fails for another reason.
- What happens when this code is compiled and executed? (1 correct answer)
import java.io.*; public class Person implements Serializable { final String name; int age; public Person(String name, int age) { this.age = age; this.name = name; } public String toString() { return "Hello it's " + name + "! I am " + age + " years old."; } public static void main(String[] args) throws Exception { Person before = new Person("Shakira", 30); ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/person")); out.writeObject(before); ObjectInputStream input = new ObjectInputStream( new FileInputStream("/person")); Person after = (Person)input.readObject(); System.out.println(after); } }- It prints “Hello it’s Shakira! I am 30 years old”.
- It prints “Hello it’s null! I am 30 years old”.
- It prints “Hello it’s ! I am 30 years old”.
- Compilation fails.
- What happens when this code is compiled and executed? (1 correct answer)
import java.io.*; public class Person implements Serializable { transient String name; transient int age; public Person(String name, int age) { this.age = age; this.name = name; } public String toString() { return "Hello it's " + name + "! I am " + age + " years old."; } public static void main(String[] args) throws Exception { Person before = new Person("Shakira", 30); ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/person")); out.writeObject(before); ObjectInputStream input = new ObjectInputStream( new FileInputStream("/person")); Person after = (Person)input.readObject(); System.out.println(after); } }- It prints “Hello it’s Shakira! I am 30 years old”.
- It prints “Hello it’s null! I am 0 years old”.
- It prints “Hello it’s null! I am -1 years old”.
- It prints “Hello it’s ! I am 0 years old”.
- It prints “Hello it’s ! I am -1 years old”.
- A NotSerializableException is thrown because all the state of Person is transient.
- Compilation fails.
- Consider the two classes.
public class Parent implements Serializable { protected String hello = "Hello!"; } public class Child extends Parent { int age = 11; public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=11 hello=Hello!”.
- It prints “age=11 hello=null”.
- It prints “age=0 hello=Hello!”.
- It prints “age=0 hello=null”.
- An exception is thrown at runtime, because Child does not implement Serializable directly.
- Consider the two classes.
public class Parent { protected String hello = "Hello!"; } public class Child extends Parent implements Serializable { int age = 11; public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=11 hello=Hello!”.
- It prints “age=11 hello=null”.
- It prints “age=0 hello=Hello!”.
- It prints “age=0 hello=null”.
- An exception is thrown at runtime, because Parent does not implement Serializable.
- Consider the two classes.
public class Parent { protected String hello = "Hello!"; } public class Child extends Parent implements Serializable { transient int age = 11; public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=11 hello=Hello!”.
- It prints “age=11 hello=null”.
- It prints “age=0 hello=Hello!”.
- It prints “age=0 hello=null”.
- An exception is thrown at runtime, because the field age of Child is transient.
- Consider the two classes.
public class Parent { protected transient String hello = "Hello!"; } public class Child extends Parent implements Serializable { int age = 11; public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=11 hello=Hello!”.
- It prints “age=11 hello=null”.
- It prints “age=0 hello=Hello!”.
- It prints “age=0 hello=null”.
- Compilation fails because Parent declares a transient field but does not implement Serializable.
- Consider the two classes.
public class Parent { protected String hello = "Hello!"; } public class Child extends Parent implements Serializable { int age = 11; public Child(int age) { this.age = age; } public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child(7)); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=7 hello=Hello!”.
- It prints “age=11 hello=Hello!”.
- Compilation fails because Child does not have a no-argument constructor.
- Consider the two classes.
public class Parent implements Serializable { protected String hello = "Hello!"; } public class Child extends Parent { int age = 11; public Child(int age) { this.age = age; } public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child(7)); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=7 hello=Hello!”.
- It prints “age=11 hello=Hello!”.
- Compilation fails because Child does not have a no-argument constructor.
- Consider the two classes.
public class Parent implements Serializable { protected String hello = "Hello!"; } public class Child extends Parent { int age = 11; public Child(int age, String hello) { this.age = age; this.hello = hello; } public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child(7, "Zorro")); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=7 hello=Hello!”.
- It prints “age=7 hello=Zorro!”.
- It prints “age=11 hello=Hello!”.
- It prints “age=11 hello=Zorro!”.
- Consider the two classes.
public class Parent { protected String hello = "Hello!"; } public class Child extends Parent implements Serializable { int age = 11; public Child(int age, String hello) { this.age = age; this.hello = hello; } public String toString() { return "age=" + age + " hello=" + hello; } }What happens when the following statements get executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Child(7, "Zorro")); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- It prints “age=7 hello=Hello!”.
- It prints “age=7 hello=Zorro!”.
- It prints “age=11 hello=Hello!”.
- It prints “age=11 hello=Zorro!”.
- Consider the following classes.
public class Team implements Serializable { Coach coach = null; } public class Coach { }What happens when an object of Team gets serialized? (1 correct answer)
- Compilation fails because Team has a non-serializable field.
- A NotSerializableException is thrown at runtime, because Coach does not implement Serializable.
- A NullPointerException is thrown at runtime, because the field coach is null.
- Serialization succeeds.
- Consider the following classes.
public class Team implements Serializable { Coach coach = new Coach(); } public class Coach { }What happens when an object of Team gets serialized? (1 correct answer)
- Compilation fails because Team has a non-serializable field.
- A NotSerializableException is thrown at runtime, because Coach does not implement Serializable.
- Serialization succeeds, but the coach object does not get serialized.
- Serialization succeeds, including the coach object.
- Consider the following classes.
public class Team implements Serializable { Coach coach = new Coach(); Player[] players = new Player[5]; } public class Coach implements Serializable { } public class Player { }What happens when an object of Team gets serialized? (1 correct answer)
- A NotSerializableException is thrown at runtime, because Player does not implement Serializable.
- A NotSerializableException is thrown at runtime, because arrays cannot get serialized.
- Serialization succeeds, but the array of players does not get serialized.
- Serialization succeeds, including the array of players.
- Consider the following classes.
public class Team implements Serializable { Coach coach = new Coach(); Player[] players = new Player[5]; public Team() { players[0] = new Player(); players[1] = new Player(); players[2] = new Player(); players[3] = new Player(); players[4] = new Player(); } } public class Coach implements Serializable { } public class Player { }What happens when an object of Team gets serialized? (1 correct answer)
- A NotSerializableException is thrown at runtime, because Player does not implement Serializable.
- A NotSerializableException is thrown at runtime, because arrays cannot get serialized.
- Serialization succeeds, but the array of players does not get serialized.
- Serialization succeeds, including the array of players.
- Consider the following classes.
public class A implements Serializable { private final B field = new B(); } public class B implements Serializable { private final A field = new A(); }What happens when an object of A gets serialized? (1 correct answer)
- A StackOverflowError is thrown, not related to serialization.
- A StackOverflowError is thrown, because serialization gets into a cyclic loop.
- Compilation fails because serializable fields cannot be final.
- Serialization succeeds.
- Consider this class.
public class Collection implements Serializable { private volatile NavigableSet<Integer> numbers; public Collection() { numbers = new TreeSet<Integer>(); numbers.add(1); numbers.add(1453); numbers.add(007); } }What happens when an object of this class gets serialized? (1 correct answer)
- Compilation fails because Collection is a reserved word in Java.
- A NotSerializableException is thrown at runtime, because a TreeSet cannot be serialized.
- A NotSerializableException is thrown at runtime, because primitive numbers (1, 1453 etc) cannot get serialized.
- An InvalidClassException is thrown at runtime due to the volatile modifier.
- Serialization succeeds.
- Consider these classes.
public class Grandparent implements Serializable { public Grandparent(int number) { } } public class Parent extends Grandparent { public Parent(int number) { super(number); } } public class Child extends Parent { public Child(int number) { super(number); } }What happens when an object of class Child is serialized? (1 correct answer)
- An exception is thrown at runtime, because Grandparent does not provide a no-arguments constructor.
- An exception is thrown at runtime, because Parent does not provide a no-arguments constructor.
- An exception is thrown at runtime, because Child does not provide a no-arguments constructor.
- Serialization succeeds.
- Consider these classes.
public class Grandparent { public Grandparent(int number) { } } public class Parent extends Grandparent implements Serializable { public Parent(int number) { super(number); } } public class Child extends Parent { public Child(int number) { super(number); } }What happens when an object of class Child is serialized? (1 correct answer)
- An exception is thrown at runtime, because Grandparent does not provide a no-argument constructor.
- An exception is thrown at runtime, because Parent does not provide a no-argument constructor.
- An exception is thrown at runtime, because Child does not provide a no-argument constructor.
- Serialization succeeds.
- Consider these classes.
public class Grandparent implements Serializable { public Grandparent() { System.out.println("A"); } } public class Parent extends Grandparent { public Parent() { System.out.println("B"); } } public class Child extends Parent { public Child() { System.out.println("C"); } }What gets printed after the following code is executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("child")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("child")); System.out.print(in.readObject());- A B C
- C B A
- A B C A
- Consider these classes.
public class Grandparent { public Grandparent() { System.out.println("A"); } } public class Parent extends Grandparent implements Serializable { public Parent() { System.out.println("B"); } } public class Child extends Parent { public Child() { System.out.println("C"); } }What gets printed after the following code is executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("child")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("child")); System.out.print(in.readObject());- A B C
- C B A
- A B C A
- Consider these classes.
public class Grandparent { public Grandparent() { System.out.println("A"); } } public class Parent extends Grandparent { public Parent() { System.out.println("B"); } } public class Child extends Parent implements Serializable { public Child() { System.out.println("C"); } }What gets printed after the following code is executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("child")); out.writeObject(new Child()); ObjectInputStream in = new ObjectInputStream( new FileInputStream("child")); System.out.print(in.readObject());- A B C
- C B A
- A B C A B
- A B C B A
- Consider these classes.
public class Grandparent { public Grandparent() { System.out.println("A"); } public Grandparent(int number) { System.out.println("1"); } } public class Parent extends Grandparent { public Parent() { System.out.println("B"); } public Parent(int number) { super(number); System.out.println("2"); } } public class Child extends Parent implements Serializable { public Child() { System.out.println("C"); } public Child(int number) { super(number); System.out.println("3"); } }What gets printed after the following code is executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("child")); out.writeObject(new Child(123)); ObjectInputStream in = new ObjectInputStream( new FileInputStream("child")); System.out.print(in.readObject());- 1 2 3
- 1 2 3 A
- 1 2 3 A B
- 1 2 3 A B C
- Consider this class.
public class Last implements Serializable{ String name; int age; public Last(String name, int age) { this.name = name; this.age = age; } private void writeObject(ObjectOutputStream stream) throws IOException { stream.writeUTF(name); stream.writeInt(age); } private void readObject(ObjectInputStream stream) throws IOException { name = stream.readUTF(); age = stream.readInt(); } public String toString() { return name + " " + age; } }What gets printed after the following code is executed? (1 correct answer)
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("/object")); out.writeObject(new Last("Old", 150)); ObjectInputStream in = new ObjectInputStream( new FileInputStream("/object")); System.out.print(in.readObject());- Old 150
- null 0
- A runtime exception is thrown because writeObject() and readObject() are private.
- A runtime exception is thrown in readObject() because the age should be read first.
- A runtime exception is thrown because defaultWriteObject() and defaultReadObject() are never called.
- Compiler error, because readObject() does not throw a ClassNotFoundException.
- Compiler error, because defaultWriteObject() and defaultReadObject() must be called first.
- Compiler error, because the visibility of writeObject() and readObject() cannot be reduced.
- Compiler error, because writeObject() and readObject() should be the last methods of this class.
Answers
- b
- b
- a
-
- path -> \file.txt
- absolute -> C:\file.txt
- canonical -> C:\file.txt
-
- path -> file.txt
- absolute -> C:\documents\file.txt
- canonical -> C:\documents\file.txt
-
- path -> ..\file.txt
- absolute -> C:\parent\child\..\file.txt
- canonical -> C:\parent\file.txt
-
- path -> /file.txt
- absolute -> /file.txt
- canonical -> /file.txt
-
- path -> file.txt
- absolute -> /usr/prog/file.txt
- canonical -> /usr/prog/file.txt
-
- path -> ../file.txt
- absolute -> /test/../file.txt
- canonical -> /file.txt
- a
- c
- Writer
- InputStream
- Yes
- d
- b
- d
- a
- d
- d
- a
- d
- No
- b
- d
- a
- c
- a
- b
- a
- a
- c
- a
- a
- a
- b
- a
- d
- b
- d
- a
- a
- e
- d
- a
- a
- c
- c
- c
- a
References
A friendly community of people preparing for SCJP can be found at the JavaRanch.
Please feel free to communicate for any suggestion!
Thanks, Nikos.
Tags: SCJP

10 October 2008 at 11:00 pm
[...] Free SCJP Mock exam for I/O [...]
30 November 2008 at 4:13 pm
Thank you, very useful content.
21 February 2009 at 5:27 am
Question 28:
The answer should be “d” Compilation fails.
Because this line “final String name;”.
And thanks for mock exam it very useful
5 March 2009 at 1:29 am
Thanks a lot for these question set its very useful. However
Question 2: answer should be c, NullPointerException at second line . when name is null. I tested it, it throws a null pointer exception. Also according to API .
Question 11, answer should be d, FileOutputStream is used to write stream to a file.
Please Let me know if I am wrong.
Thanks,
26 March 2009 at 7:28 pm
Question nr 28 is correct. The final variable is initialized in constructor so all is good. You have 3 places where can You initialize final variable:
1) in declaration
2) init block
3) constructor
8 August 2009 at 11:01 pm
Good one !! Hats off to you Niko !!
9 November 2009 at 6:18 am
Thanx for the questions, keep up good work
1 December 2009 at 11:43 pm
There’s an error in question 46. The output is: A B C and the return of toString() method, eg: Child@a62fc3
1 December 2009 at 11:47 pm
47 has the same problem as 46
5 December 2009 at 9:20 pm
Answer of question # 1 is NullPointerException at third line…
15 December 2009 at 10:31 pm
I was shocked when I got through first couple questions – shocked that I did not know such simple/basic things. Later, was much better!
Thanks. Good one.