Q1. Given:
Which option enables the code to compile?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C,D
Q2. Given:
public class TestOperator {
public static void main(String[] args) {
int result = 30 -12 / (2*5)+1;
System.out.print("Result = " + result);
}
}
What is the result?
A. Result = 2
B. Result = 3
C. Result = 28
D. Result = 29
E. Result = 30
Answer: E
Q3. Given:
And given the code fragment:
What is the result?
A. 4W 100 Auto 4W 150 Manual
B. Null 0 Auto 4W 150 Manual
C. Compilation fails only at line n1
D. Compilation fails only at line n2
E. Compilation fails at both line n1 and line n2
Answer: E
Explanation:
On line n1 implicit call to parameterized constructor is missing and n2 this() must be the first line.
Q4. Given:
How many objects have been created when the line / / do complex stuff is reached?
A. Two
B. Three
C. Four
D. Six
Answer: C
Q5. Given the code fragment:
Which option can replace xxx to enable the code to print 135?
A. int e = 0; e < = 4; e++
B. int e = 0; e < 5; e + = 2
C. int e = 1; e < = 5; e + = 1
D. int e = 1; e < 5; e+ =2
Answer: B
Q6. Given:
public class Marklist {
int num;
public static void graceMarks(Marklist obj4) {
obj4.num += 10;
}
public static void main(String[] args) {
MarkList obj1 = new MarkList();
MarkList obj2 = obj1;
MarkList obj1 = null;
obj2.num = 60;
graceMarks(obj2);
}
}
How many objects are created in the memory runtime?
A. 1
B. 2
C. 3
D. 4
Answer: B
Explanation: obj1 and obj3.
when you do e2 = e1 you're copying object references - you're not making a copy of the object - and so the variables e1 and e2 will both point to the same object.
Q7. Which usage represents a valid way of compiling java source file with the name "Main"?
A. javac Main.java
B. java Main.class
C. java Main.java
D. javac Main
E. java Main
Answer: A
Explanation: The compiler is invoked by the javac command. When compiling a Java class, you must include the file name, which houses the main classes including the Java extension. So to run Main.java file we have to use command in option A. TO execute Java program we can use Java command but can't use it for compiling. https://docs.oracle.com/javase/tutorial/getStarted/application/index.html
Q8. Given the following class declarations:
public abstract class Animal
public interface Hunter
public class Cat extends Animal implements Hunter
public class Tiger extends Cat
Which answer fails to compile?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Answer: E
Explanation: Look at the right side of the declaration ArrayLIst() rather than ArrayList
Q9. Consider following method
Which statement is true?
A. This method is invalid.
B. This method can be used only in an interface.
C. This method can return anything.
D. This method can be used only in an interface or an abstract class.
E. None of above.
Answer: B
Explanation:
Given method is declared as default method so we can use it only inside an interface.
Hence option B is correct and option D is incorrect.
Option A is incorrect as it is valid method. Option C is incorrect as return type is void, which
means we can't return anything.
Q10. Given:
What is the result?
A. Compilation fails
B. The code compiles, but does not execute.
C. Paildrome
D. Wow
E. Mom
Answer: B