Free Practice Quiz Question List

09 Classes and Class Design Online Quiz Questions

Use this free practice quiz with 20 questions to review 09 Classes and Class Design, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Which statement best describes the relationship between a Java class and an object?

  1. A

    A class is an object created with new, while an object is its source-code definition.

  2. B

    A class is a programmer-defined type that combines state and behavior, while an object is an instance of that class.

  3. C

    A class contains only methods, while an object contains only fields.

  4. D

    A class is a superclass, while an object is always a subclass.

02
True or false
1 point

True or false: A Java constructor must have the same name as its class and cannot declare a return type, including void.

  1. A

    True

  2. B

    False

03
Fill in the blank
1 point

Complete the statement: In a Java class, fields represent the object's , and methods represent its .

04
Written response
1 point

What design principle keeps an object's implementation details together while controlling access to its state?

05
Choose one
1 point

Which situation is an example of constructor overloading?

  1. A

    A class has multiple constructors with identical parameter lists but different names.

  2. B

    A class has one constructor and several overloaded methods.

  3. C

    A class has multiple constructors with parameter lists that differ in number or type.

  4. D

    A class has a constructor that returns different types depending on the arguments.

06
Choose all
1 point

Which statements correctly describe a Java static method? Select all that apply.

  1. A

    It can directly access a static field.

  2. B

    It can directly call another static method.

  3. C

    It can directly read an instance field without an object reference.

  4. D

    It cannot use this.

07
True or false
1 point

True or false: If a Java class declares no constructor, Java supplies a no-argument default constructor.

  1. A

    True

  2. B

    False

08
Fill in the blank
1 point

Complete the statement: In a Java constructor, this(...) must be the and calls .

09
Written response
1 point

How many direct superclasses can a Java class extend?

10
Choose one
1 point

Which design best uses composition to model a car that relies on an engine?

  1. A

    Make Car extend Engine, because every car is an engine.

  2. B

    Store an Engine field inside Car and delegate start() to it.

  3. C

    Copy the source code of Engine into Car.

  4. D

    Make Engine extend Car, because an engine is a specialized car.

11
Choose all
1 point

Which activities belong to the recommended process for converting a problem into Java classes? Select all that apply.

  1. A

    Extract nouns as possible classes.

  2. B

    Extract verbs as possible methods.

  3. C

    Make every field public so that responsibilities are visible.

  4. D

    Define invariants that should always remain true.

  5. E

    Choose among relationships such as composition and inheritance.

12
Open ended
1 point

Design the public behavior and main rules for a BankAccount class. Explain what state should be protected, what its constructor and money-moving methods should validate, and how the class should prevent an invalid balance.

13
Choose one
1 point

A BankAccount has a balance of 50. What happens when withdraw(70) is called according to the class design in the material?

  1. A

    It returns true and changes the balance to -20.

  2. B

    It returns false and changes the balance to -20.

  3. C

    It returns false and leaves the balance at 50.

  4. D

    It throws an exception because every unsuccessful withdrawal is invalid input.

14
Choose one
1 point

Which expression creates an object of the Temperature class?

  1. A

    Temperature

  2. B

    new Temperature(21.5)

  3. C

    toFahrenheit

  4. D

    roomTemperature

15
Choose one
1 point

A BankAccount must prevent deposits of zero or negative amounts. Which design best preserves that rule?

  1. A

    Make balance public so every client can update it directly.

  2. B

    Keep balance private and provide a validating deposit method.

  3. C

    Make balance a local variable inside every method.

  4. D

    Remove all checks so clients can decide whether an update is valid.

16
Choose one
1 point

What happens when a Java class declares no constructor of its own?

  1. A

    Java always supplies both a no-argument and a parameterized constructor.

  2. B

    Java supplies a no-argument constructor even after a parameterized constructor is declared.

  3. C

    Java supplies an automatic no-argument constructor only when the class declares no constructor.

  4. D

    Java never supplies constructors automatically.

17
Choose one
1 point

Why can MathTools.square be declared static without an object, and what restriction follows from that choice?

  1. A

    It has no particular object and uses only its parameter, so it cannot directly use instance fields, instance methods, or this.

  2. B

    It can directly use any private instance field in the class because static methods belong to that class.

  3. C

    It automatically receives the most recently created object and can use that object's instance state.

  4. D

    It can use this to select which object to modify, even though it is called through the class name.

18
True or false
1 point

True or false: In a Java constructor, a call to another constructor in the same class using this(...) must be the first statement.

  1. A

    True

  2. B

    False

19
Written response
1 point

Which Java keyword refers to the current object inside an instance method or constructor?

20
Written response
1 point

What design term describes a class whose data and behavior are closely related and organized around one central responsibility?