This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 4 quickie questions . . . test yourself Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "4 quickie questions . . . test yourself " Watch "4 quickie questions . . . test yourself " New topic
Author

4 quickie questions . . . test yourself

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Try answering the following questions without compiling or running . . .
After you are done, check the answers at the bottom.
Best of luck . . .
Question 1
----------
public class A {
public static void main(String[] args)
{
int[] a = new int[-10];
for (int i = 0 ; i < a.length; i++)<br /> System.out.println(a[i]);<br /> };<br /> }<br /> Select all the correct answers.<br /> A> Does not compile (extra semicolon at end of main method
B> Does not compile (Negative array size initializer not allowed)
C> Compiles correctly.
D> Throws a NegativeArraySizeException at runtime
E> Compiles correct, but throws a NullPointerException at runtime.

Question 2
----------
public class B {
public interface InnerInterFace {
abstract public void interfaceMethod();
}
public static void main(String[] args)
{
B b = new B();
}

}
Select all correct answers.
A> Code will not compile (Interfaces not allowed inside classes)
B> The word abstract is not necessary as all methods in an interface are abstract by default.
C> The code compiles and runs fine producing no output.
D> b cannot be instantiated as it has an interface with an abstract method.

Question 3
----------
1> public class C {
2> public static void main(String args[])
3> {
4> Map m = new Hashtable();
5> m.put("A",new String("A"));
6> }
7> }
If lines 1-7 were to be pasted into a separate file named C.java, would C.java compile without any errors ?
A> Compiles correctly
B> Does not compile

Question 4
----------
public class D {
public static void main()
{
byte b = 21;
while (b > 1)
{
System.out.println(b);
b >>= 1;
}
}
};
What is the output of the above program ?
A> 21 10 5 2 1
B> 21 10 4 2 1
C> 21 10 5 2
D> Compiles correctly, but throws a NoSuchMethodError exception at runtime
E> Does not compile

Answers
------------
1> C, D
2> B, C
3> B (Does not compile as java.util classes are not imported. Pay special attention to the wording of the question, which clearly says lines 1 to 7 only)
4> D (Check the main method signature)
Surya B
Ranch Hand

Joined: May 10, 2000
Posts: 98
Hi Shashank,
Really good questions,keep it up.
Surya
Harry Chawla
Ranch Hand

Joined: Jun 03, 2000
Posts: 97
Hi Shashank
Thanks for the questions. They'r good information, moreso for a guy like me who has to go for Programmer certification within a month. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 4 quickie questions . . . test yourself