Java Quiz
Question 1.
Read this piece of
code carefully
if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
-
the code will compile an print "Equal".
-
the code will compile an print "Not Equal".
-
the code will cause a compiler error.
Question 2.
Read this piece of
code carefully
if(" String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
-
the code will compile an print "Equal".
-
the code will compile an print "Not Equal".
-
the code will cause a compiler error
Question 3.
Read the code below. Will be the result of attempting to compile and
run the code below.
public class AQuestion
{
public void method(Object o)
{
System.out.println("Object
Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Answers
-
The code does not compile.
-
The code compiles cleanly and shows "Object Version".
-
The code compiles cleanly and shows "String Version"
-
The code throws an Exception at Runtime.
Question 4.
Read the code below. Will be the result of attempting to compile and
run the code below.
public class AQuestion
{
public void method(StringBuffer sb)
{
System.out.println("StringBuffer
Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Answers
-
The code does not compile.
-
The code compiles cleanly and shows "StringBuffer Version".
-
The code compiles cleanly and shows "String Version"
-
The code throws an Exception at Runtime.
Question 5.
Read the following code below.
public interface AQuestion
{
public abstract void someMethod() throws
Exception;
}
A Class implementing this interface should
-
Necessarily be an abstract class.
-
Should have the method public abstract void someMethod();
-
Should have the method public void someMethod() which has to throw an exception
which is a subclass of java.lang.Exception.
-
Should have the method public void someMethod() which need not throw an
Exception.
Question 6.
An Interface can never be
private or protected.
Answers
True
False
Question 7.
A Vector class in jdk 1.2
-
is public
-
is final
-
implements java.util.List
-
is serializable
-
has only One constructor
Question 8.
A String Class
-
is final
-
is public
-
is serializable
-
has a constructor which takes a StingBuffer Object as an Argument
Question 9.
public interface AQuestion
{
void someMethod();
}
The class which implements AQuestion
-
Should have someMethod which must necessarily be public.
-
Should have someMethod which could be "friendly" or public
-
Should have someMethod which should not throw any checked exceptions.
-
Should have someMethod which cannot be sychronized as sychronized is not
in the signature of the interface defination
Question 10.
public class AQuestion
{
private int i = j;
private int j = 10;
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Answers
-
Compiler error complaining about access restriction of private variables
of AQuestion.
-
Compiler error complaining about forward referencing.
-
No error - The output is 0;
-
No error - The output is 10;
If you have any
concerns regarding any questions in this page, please mail meNOW!!!