What is the difference between a Java class and an object?
A class is a definition or blueprint; an object is a distinct instance created from that class.
Study 08 Objects and Encapsulation with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is the difference between a Java class and an object?
A class is a definition or blueprint; an object is a distinct instance created from that class.
What three characteristics define an object?
An object’s state is its stored data, behavior is supplied by its methods, and identity distinguishes it from other instances.
What is a field in Java?
A field is a variable declared inside a class; instance fields normally give each object its own stored state.
What does an instance method operate on?
An instance method operates on a particular object and can use or modify that object’s instance fields.
What is a Java constructor?
A constructor initializes a newly created object. It has the class’s name and no return type, not even `void`.
What does the `new` operator do?
The `new` operator creates an object by executing a constructor call; the resulting reference can be stored in a variable.
How is an instance method invoked?
The dot operator invokes an instance method through a reference, such as `account.deposit(40.00)`.
What does `this` refer to in an instance method?
Inside an instance method, `this` refers to the object on which the method was invoked.
What is constructor overloading?
Constructor overloading provides multiple constructors with different parameter lists, allowing several valid ways to create an object.
What happens when `alias = original` is assigned?
Assigning one reference to another copies the reference, not the object, so both variables can identify the same object.
How does primitive assignment differ from reference assignment?
Assigning one primitive variable to another copies the value, so later changes to one variable do not change the other.
What does `null` mean for a Java reference?
`null` means a reference refers to no object. Calling an instance method through it causes a `NullPointerException`.