Free Online Flashcard Deck

09 Classes and Class Design Free Online FlashCards

Study 09 Classes and Class Design with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is the difference between a class and an object?

Back

A class is a programmer-defined type that combines state and behavior. An object is a run-time instance of that class.

02
Front

What is a Java constructor?

Back

A constructor initializes a newly created object, has the same name as its class, and has no return type, including no `void`.

03
Front

What is constructor overloading?

Back

Constructor overloading means defining multiple constructors whose parameter lists differ in number or type.

04
Front

What does `this` refer to in Java?

Back

`this` refers to the current object. In `this.name = name`, it distinguishes the instance field from the parameter with the same name.

05
Front

What does encapsulation achieve?

Back

Encapsulation keeps implementation details together and controls access to them, commonly through private fields and carefully chosen public methods.

06
Front

Where can a private Java member be accessed?

Back

A private member is accessible only within its declaring class. It is not directly accessible from other classes or subclasses.

07
Front

How do instance and static fields differ?

Back

An instance field belongs to one object, so each object has its own value. A static field belongs to the class and is shared by its objects.

08
Front

What cannot a static method directly access?

Back

A static method has no particular object, so it cannot directly use instance fields, instance methods, or `this`. It can directly use static members.

09
Front

What do `static` and `final` mean together?

Back

In `static final`, `static` makes the field belong to the class, while `final` prevents the field from being reassigned after initialization.

10
Front

What is a class's public interface?

Back

A public interface is the set of public constructors and methods that other code can use. It should be small, clear, and difficult to misuse.

11
Front

What makes a class cohesive?

Back

A cohesive class contains closely related data and behavior and generally has one central responsibility.

12
Front

What is composition in class design?

Back

Composition builds a class from objects of other classes. It models a has-a or uses-a relationship, such as a `Car` containing an `Engine`.