Q1. What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?
A. Encapsulation
B. Inheritance
C. Abstraction
D. Instantiation
E. Polymorphism
Answer: A
Q2. Given the definitions of the MyString class and the Test class:
What is the result?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C
Q3. Given:
public class Test {
static boolean bVar;
public static void main(String[] args) {
boolean bVar1 = true;
int count =8;
do {
System.out.println("Hello Java! " +count);
if (count >= 7) {
bVar1 = false;
}
} while (bVar != bVar1 && count > 4);
count -= 2;
}
}
What is the result?
A. Hello Java! 8 Hello Java! 6 Hello Java! 4
B. Hello Java! 8 Hello Java! 6
C. Hello Java! 8
D. Compilation fails
Answer: C
Explanation: Hello Java! 8
Q4. Given:
And the commands:
Javac Jump.java
Java Jump crazy elephant is always
What is the result?
A. Lazy lion is jumping
B. Lion is always jumping
C. Crazy elephant is jumping
D. Elephant is always jumping
E. Compilation fails
Answer: B
Q5. Given:
What is the result?
A. simaple A
B. Capital A
C. simaple A default Capital A
D. simaple A default
E. Compilation fails.
Answer: C
Explanation:
Here we have to use two ternary operators combined. SO first we can use to check first
condition which is x > 10, as follows;
x>10?">": (when condition false) Now we have to use another to check if x<10 as follows;
x<10?V:"=" We can combine these two by putting last ternary statement in the false
position of first ternary statement as follows;
x>10?">":x<10?'<':"="
https;//docs.oraclexom/javase/tutorial/java/nutsandbolts/if.html
Q6. Given:
How many MarkList instances are created in memory at runtime?
A. 1
B. 2
C. 3
D. 4
Answer: A
Q7. Given the code fragment:
What is the result?
A. Reading Card Checking Card
B. Compilation fails only at line n1.
C. Compilation fails only at line n2.
D. Compilation fails only at line n3.
E. Compilation fails at both line n2 and line n3.
Answer: D
Q8. Given the following code:
What are the values of each element in intArr after this code has executed?
A. 15, 60, 45, 90, 75
B. 15, 90, 45, 90, 75
C. 15, 30, 75, 60, 90
D. 15, 30, 90, 60, 90
E. 15, 4, 45, 60, 90
Answer: C
Q9. Given:
What is the result?
A. The sum is 2
B. The sum is 14
C. The sum is 15
D. The loop executes infinite times
E. Compilation fails
Answer: E
Q10. Given:
interface Pet { }
class Dog implements Pet { }
public class Beagle extends Dog{ }
Which three are valid?
A. Pet a = new Dog();
B. Pet b = new Pet();
C. Dog f = new Pet();
D. Dog d = new Beagle();
E. Pet e = new Beagle();
F. Beagle c = new Dog();
Answer: A,D,E
Explanation:
Incorrect:
Not B, not C: Pet is abstact, cannot be instantiated.
Not F: incompatible type. Required Beagle, found Dog.