Things to Consider - Module 2

 

Basic Understanding of Classes and Objects:

  1. What is a class in Java? How is it different from an object?

  2. What are the main components of a Java class?

  3. How do you define a constructor, and what is its role in a Java class?

  4. Can a class have more than one constructor? What is this concept called?

Variables and Methods:

  1. What is the difference between instance variables and class variables?

  2. What are 'getter' and 'setter' methods, and why are they used?

  3. How does a static method differ from an instance method?

  4. What is 'method overloading,' and can you provide a simple example?

Access Modifiers:

  1. What are access modifiers, and what types are available in Java?

  2. What is the difference between public, private, and protected access modifiers?

Inheritance and Encapsulation:

  1. What is inheritance, and how can it be implemented in Java?

  2. What is encapsulation, and why is it important?

Miscellaneous:

  1. What is the this keyword, and where is it used?

  2. How do you initialize an object using a constructor?

  3. What is a 'package' in Java, and how does it relate to classes?

  4. 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:

  1. Which keyword is used to create a new object in Java?

    • [ ] new

    • [ ] create

    • [ ] init

    • [ ] object

  2. What is the purpose of a constructor?

    • [ ] To import packages

    • [ ] To initialize an object

    • [ ] To modify an object

    • [ ] None of the above

  3. Which access modifier allows a class member to be accessible only within its own package?

    • [ ] private

    • [ ] protected

    • [ ] public

    • [ ] Default (no modifier)

  4. 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

  5. What does the this keyword refer to?

    • [ ] The current object

    • [ ] The current class

    • [ ] The superclass

    • [ ] The subclass

True or False:

  1. In Java, a class can inherit from multiple parent classes.

    • [ ] True

    • [ ] False

  2. Method overloading allows methods in the same class to have the same name but different parameter lists.

    • [ ] True

    • [ ] False

  3. Instance variables of a class are initialized with default values if you don't initialize them.

    • [ ] True

    • [ ] False

  4. The constructor name must be different from the class name.

    • [ ] True

    • [ ] False

  5. 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