Object and Classes I

Objects and Classes I

Objects and Classes in Programming, Constructors, Encapsulation and Access Modifiers, Static Members, Inheritance and Polymorphism, Advanced Topics: Anonymous Objects and Inner Classes, Object Cloning, Real-world Object Representation, E-commerce System

1 / 10

Which of the following is true about objects in object-oriented programming?

2 / 10

What happens if you declare a class without any fields or methods?

3 / 10

What is the primary purpose of a constructor in a class?

4 / 10

Which statement about constructors is true?

5 / 10

What will happen if a class does not explicitly define a constructor?

6 / 10

Which access modifier ensures that a field is accessible only within its class?

7 / 10

Which of the following statements is true about encapsulation?

8 / 10

What is the purpose of getter and setter methods in Java?

9 / 10

Which statement about static methods and variables is correct?

10 / 10

What will the following code output?

public class Test {
static int count = 0;
public Test() {
count++;
}
public static void main(String[] args) {
Test obj1 = new Test();
Test obj2 = new Test();
System.out.println(Test.count);
}
}

Your score is

Scroll to Top