|
Page 1 of 2 Test your Java skills and check if you are in touch with the core language. Here's the second of our mini Java quizzes.
These questions are courtesy of Whizlabs Software and are meant to help you prepare for the Sun Certified Java Programmer Exam 5.0 (SCJP).
If you are looking for a user contributed database of 100s of Java questions, check out the Java Interview Questions Bank or check out Java Questions Quiz One.
Question No. 1: What is the result of compiling and running the following code?
class PrintTest{
public static void main(String[] args) {
double d=222.4578;
System.out.printf("% .2f",d);
}
}
A.Does not compile
B.Throws IllegalFormatConversionException
C.Prints 222.46
D.Prints 222.45
E.Prints 2.224578
F.Prints .2224578
Question No. 2
What is the result of compiling and running the following code, assuming that the file bb.txt does not exist?
class WriterTest{
public static void main(String[] args) throws IOException{
Writer w=new BufferedWriter(new FileWriter("bb.txt")); // Line1
w.write(1); // Line2
w.close();
}
}
A.Compiler error
B.FileNotFoundException thrown at line 1
C.IOException thrown at line 2
D.None of these
Question No. 3
Which of the following statements are true about the default implementation of the public int hashCode() method of the Object class?
A.The Object class does not provide any implementation for the hashCode method; every class must override it.
B.As far as it may be practically possible, the hashCode method defined by the Object class does return distinct integers for distinct objects.
C.For two object references referring to the same object, the hashCode method returns the same integer.
D.It returns a fixed number that internally represents the Object class for the JVM.
E.Only choice D is correct.
The next page has the answers and explanations
<< Start < Previous 1 2 Next > End >> |