Toggle Navigation
Games
Blog
Class PIN
Join for Free
Sign in
Toggle Navigation
Games
PIN
Join for Free
Blog
Pricing
Contact us
Help center
Sign in
Study
PR1-W6-Part1-OOP_Classes&Objects
0
%
0
0
0
Back
Restart
16. Given String s1 = new String("hi"); String s2 = "hi";, what is s1 == s2? (3)
B (new String("hi") creates a separate object on the heap; s2 references the interned literal)
Oops!
Okay!
6. What is the output? (2)
5 (int is primitive → assignment copies the value. Changing y does not affect x.)
Oops!
Okay!
5. Which of the following best describes encapsulation? (2)
B (Encapsulation uses private fields and public getters/setters or methods to control access)
Oops!
Okay!
7. What is the output? (2)
Fido (d1 and d2 refer to the same object → changing through one affects the other.)
Oops!
Okay!
2. Which of the following is not a primitive type in Java? (1)
C. String
Oops!
Okay!
15. Given String s1 = "hi"; String s2 = "hi";, what is s1 == s2? (3)
B ( String literals are interned; identical literals refer to the same object in the string pool, so == is true)
Oops!
Okay!
20. Predict the output: (4)
Hello from B (Dynamic dispatch — method chosen at runtime based on actual object type, not reference type)
Oops!
Okay!
Won 25 points
25
Oops!
Okay!
23. Which of these is not part of the typical class structure? (1)
D (A class describes fields, methods, constructors. Memory addresses are runtime details, not class structure)
Oops!
Okay!
9. What is printed? (3)
70.0 (Withdraw subtracts from balance, leaving 70)
Oops!
Okay!
8. What happens? (3)
Compile error (No default constructor is available since the class declared a constructor with parameters)
Oops!
Okay!
1. Which Java keyword is used to create a new object (an instance) of a class? (1)
C. new (Example: Dog d = new Dog();)
Oops!
Okay!
18.What will be printed? (4)
10 (Constructor assigns value; method prints it)
Oops!
Okay!
11. Which keyword refers to the current instance inside an instance method or constructor? (2)
C. this
Oops!
Okay!
10. What is the output? (3)
2 (Static field count is shared across all objects. Each constructor increments once)
Oops!
Okay!
13. What does the expression a == b test when a and b are object references? (3)
B ( == compares references for objects. equals() can be overridden to compare content.)
Oops!
Okay!
14. Which statement about equals() is correct? (3)
B (Object.equals() tests this == obj. Many classes (e.g., String) override it to compare content)
Oops!
Okay!
21. Which of the following is a valid reason to make a field private and use getters/setters? (2)
C (Private fields prevent arbitrary external modification; setters can validate values)
Oops!
Okay!
3. What does a class represent in object-oriented programming? (1)
B (A class defines fields and methods. Instances (objects) are created from that blueprint.)
Oops!
Okay!
24. Which access modifier allows visibility only within the same class? (2)
C
Oops!
Okay!
12. Which is true about static fields? (2)
B (Only one copy of a static field exists per class loader; all instances share it)
Oops!
Okay!
4. Which statement about the main method is correct? (2)
B (JVM calls public static void main(String[] args) without creating an object, so main is static)
Oops!
Okay!
Won 5 points
5
Oops!
Okay!
17.Which line causes compile error? (3)
The System.out.println(x); line (x is an instance field; main is static → cannot access directly without an object)
Oops!
Okay!
Your experience on this site will be improved by allowing cookies.
Allow cookies