Things to Consider - Module 2
Basic Understanding of Classes and Objects:
What is a class in Java? How is it different from an object?
What are the main components of a Java class?
How do you define a constructor, and what is its role in a Java class?
Can a class have more than one constructor? What is this concept called?
Variables and Methods:
What is the difference between instance variables and class variables?
What are 'getter' and 'setter' methods, and why are they used?
How does a
static
method differ from an instance method?What is 'method overloading,' and can you provide a simple example?
Access Modifiers:
What are access modifiers, and what types are available in Java?
What is the difference between
public
,private
, andprotected
access modifiers?
Inheritance and Encapsulation:
What is inheritance, and how can it be implemented in Java?
What is encapsulation, and why is it important?
Miscellaneous:
What is the
this
keyword, and where is it used?How do you initialize an object using a constructor?
What is a 'package' in Java, and how does it relate to classes?
What does it mean for a method or variable to be
final
?
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?
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
COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark