Which two will compile, and can be run successfully using the command:
java Fred1 hello walls
A.
class Fred1{
public static void main (String args) {
System.out.println(args[1]);
}
}
B.
class Fred1{
public static void main (String [] args) {
System.out.println(args[1]);
}
}
C.
class Fred1 {
public static void main (String [] args) {
System.out.println (args);
}
}
D.
class Fred1 {
public static void main (String [] args) {
System.out.println (args [2]);
}
}
Explanation:
Incorrect answers:
A: Will not compile. array is required, not a string.
D: Array out of bounds at runtime.
B,D
OutPuts:
A- Compile Time Error.
B- hello
C- [Ljava.lang.String;@60607135
D- walls
B,C
D- array index out of bound
B,D
compile, and successfully
OutPuts:
A- Compile Time Error.
B- hello
C- [Ljava.lang.String;@60607135
D- walls
The Answer is B, C.
Answers are B,C..
As on letter D it tries to access index 2 on the array, it will throw an Exception as the size of the array are only 2.
B,C
Hi, I have passed OCAJP 7 (1Z0-803) EXAM with 98%. I would like to share my exam experience with those who are going to take this exam. I learned the Mala Gupta’s book and PassLeader 1Z0-803 dumps. They were describing and explaning the key points of the exam very clearly. To be honest, I read Mala Gupta’s book mainly because of the interest how the basic things in Java are handled internally and I started to take the PassLeader 1Z0-803 dumps (http://www.passleader.com/1z0-803.html), around one week before the exam. Good luck to future Oracle exam takers!