Free Practice Quiz Question List

7 Objects and Classes Online Quiz Questions

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

20 questions
01
Choose one
1 point

What is the effect of the Java declaration BankAccount checking;?

  1. A

    It creates a BankAccount object with default values.

  2. B

    It declares a BankAccount reference variable without creating an object.

  3. C

    It creates a BankAccount object only if checking is later used.

  4. D

    It creates two BankAccount objects because BankAccount is a class.

02
Choose one
1 point

Which statement correctly describes a Java constructor?

  1. A

    It must be declared static and return the new object.

  2. B

    It must have a return type of void.

  3. C

    It has the same name as the class and no return type.

  4. D

    It can be called only after an object already exists.

03
Choose one
1 point

Why is the balance field declared private in the BankAccount example?

  1. A

    It prevents direct outside access to balance so methods can enforce valid changes.

  2. B

    It makes balance shared by every BankAccount object.

  3. C

    It causes balance to be initialized automatically to zero in every case.

  4. D

    It allows any class to change balance through the dot operator.

04
Choose all
1 point

Which two statements apply to the balance field in the given BankAccount class? Select all correct choices.

  1. A

    Each BankAccount object has its own balance value.

  2. B

    All BankAccount objects automatically use one shared balance.

  3. C

    Changing one object's balance normally leaves another object's balance unchanged.

  4. D

    The balance must be declared static to belong to an object.

05
Choose all
1 point

A new BankAccount is constructed with an opening balance, and then deposit(50.00) is called. Which two effects are supported by the class definition? Select all correct choices.

  1. A

    It creates a second BankAccount object.

  2. B

    It initializes the new object's balance from openingBalance.

  3. C

    It makes the balance shared by all accounts.

  4. D

    It can increase the object's balance when a positive amount is deposited.

06
True or false
1 point

True or false: If BankAccount account = null;, calling account.getBalance() causes a NullPointerException at run time.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: In this.owner = owner;, the left-hand owner is the constructor parameter and the right-hand owner is the object's field.

  1. A

    True

  2. B

    False

08
Written response
1 point

Which Java keyword would declare accountCount as one field shared by all BankAccount objects?

09
Written response
1 point

What Java exception is caused by calling an instance method through a reference variable that contains null?

10
Fill in the blank
1 point

Complete the statement: In an object, fields represent , while methods represent .

11
Fill in the blank
1 point

Complete the statement: The special code that initializes a new object's fields when new creates it is called a .

12
Open ended
1 point

Using the Student class in the material, explain why student.getCredits() returns 15 and student.isFullTime() returns true after Student student = new Student("Avery"); student.addCredits(15);.

13
Choose one
1 point

Given public static void printBalance(BankAccount account), what may the parameter account refer to when the method is called?

  1. A

    The parameter must be a primitive number containing the balance.

  2. B

    The parameter can refer to a BankAccount object or a compatible subclass object.

  3. C

    The parameter is automatically a newly constructed BankAccount object.

  4. D

    The parameter can refer only to the BankAccount class definition, never an object.

14
Choose one
1 point

In the no-argument Point constructor, what does this(0, 0); do?

  1. A

    It calls another constructor in the same class.

  2. B

    It refers to the current object's x field.

  3. C

    It creates a new Point object outside the class.

  4. D

    It invokes the superclass constructor with two arguments.

15
Choose one
1 point

Which statement best distinguishes a Java class from an object?

  1. A

    A class is one particular entity created at run time, while an object is its blueprint.

  2. B

    A class defines the structure and behavior of objects, while an object is a particular instance.

  3. C

    A class stores only shared data, while an object stores only methods.

  4. D

    A class is a method that creates objects, while an object is a variable type.

16
True or false
1 point

True or false: In Java, the declaration BankAccount checking; by itself creates a new BankAccount object.

  1. A

    True

  2. B

    False

17
Choose one
1 point

Given BankAccount first = new BankAccount("Maya", 500.00); and BankAccount second = new BankAccount("Luis", 800.00);, what normally happens if first changes its balance?

  1. A

    Both objects must always have the same balance because they share a class.

  2. B

    Only the first object can have a balance because balance is declared in the class.

  3. C

    Each object has its own balance value because balance is an instance field.

  4. D

    The balance belongs to the class because every object can access the field.

18
Written response
1 point

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

19
Choose one
1 point

Which declaration rule identifies a Java constructor?

  1. A

    It must have a different name from the class and return the new object.

  2. B

    It must be declared static so that new can invoke it.

  3. C

    It must return void and may have any name chosen by the programmer.

  4. D

    It has the same name as the class and has no return type.

20
Written response
1 point

What Java exception occurs when BankAccount account = null; is followed by account.getBalance();?