Panel | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Basic Understanding of Classes and Objects:
Variables and Methods:
Access Modifiers:
Inheritance and Encapsulation:
Miscellaneous:
|
Certainly! Here are some quiz questions focusing on beginner-level concepts related to Java classes:
Multiple Choice Questions:
Which keyword is used to create a new object in Java?
[ ]
new
[ ]
create
[ ]
init
[ ]
object
What is the purpose of a constructor?
[ ] To import packages
[ ] To initialize an object
[ ] To modify an object
[ ] None of the above
Which access modifier allows a class member to be accessible only within its own package?
[ ]
private
[ ]
protected
[ ]
public
[ ] Default (no modifier)
What is the output of the following code snippet?
Code Block language java public class MyClass { public static int x = 5; public int y = 10; } MyClass obj1 = new MyClass(); MyClass obj2 = new MyClass(); obj1.x = 1; obj1.y = 2; System.out.println(obj2.x + ", " + obj2.y);
[ ]
5, 10
[ ]
1, 2
[ ]
1, 10
[ ]
5, 2
What does the
this
keyword refer to?[ ] The current object
[ ] The current class
[ ] The superclass
[ ] The subclass
True or False:
In Java, a class can inherit from multiple parent classes.
[ ] True
[ ] False
Method overloading allows methods in the same class to have the same name but different parameter lists.
[ ] True
[ ] False
Instance variables of a class are initialized with default values if you don't initialize them.
[ ] True
[ ] False
The constructor name must be different from the class name.
[ ] True
[ ] False
The keyword
final
can be used to prevent a method from being overridden.[ ] True
[ ] False