What is the difference between a class and an object?
A class is a programmer-defined type that combines state and behavior. An object is a run-time instance of that class.
Study 09 Classes and Class Design with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is the difference between a class and an object?
A class is a programmer-defined type that combines state and behavior. An object is a run-time instance of that class.
What is a Java constructor?
A constructor initializes a newly created object, has the same name as its class, and has no return type, including no `void`.
What is constructor overloading?
Constructor overloading means defining multiple constructors whose parameter lists differ in number or type.
What does `this` refer to in Java?
`this` refers to the current object. In `this.name = name`, it distinguishes the instance field from the parameter with the same name.
What does encapsulation achieve?
Encapsulation keeps implementation details together and controls access to them, commonly through private fields and carefully chosen public methods.
Where can a private Java member be accessed?
A private member is accessible only within its declaring class. It is not directly accessible from other classes or subclasses.
How do instance and static fields differ?
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.
What cannot a static method directly access?
A static method has no particular object, so it cannot directly use instance fields, instance methods, or `this`. It can directly use static members.
What do `static` and `final` mean together?
In `static final`, `static` makes the field belong to the class, while `final` prevents the field from being reassigned after initialization.
What is a class's public interface?
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.
What makes a class cohesive?
A cohesive class contains closely related data and behavior and generally has one central responsibility.
What is composition in class design?
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`.