Chapter 5 Flashcards
What is the definition of a class in Java?
A class is a blueprint for an object.
What does an object have in terms of state and behavior?
State = attributes = data; Behaviors = operations = class methods.
What are the two types of constructors in Java?
- Default constructor
- Parameterized constructor.
What is the purpose of the toString method in Java?
The toString method returns a string that contains the data in the object.
What are accessors and mutators?
- Accessor: returns the current value of a variable.
- Mutator: changes the value of a variable.
What is instance data in the context of a class?
Instance data refers to data that is unique to each object instance.
What does the final modifier do in Java?
The final modifier is used to define constants.
How many visibility modifiers does Java have and what are they?
Java has three visibility modifiers: * public
* protected
* private.
What is the difference between public and private visibility in Java?
- Public: can be referenced anywhere.
- Private: can be referenced only within that class.
What is meant by local data in Java?
Local data refers to data declared within a method that can only be used in that method.
What is the scope of data in a Java program?
The scope of data is the area in a program where that data can be referenced.
What is the purpose of a method header?
A method header begins with the method’s name, return type, and parameter list.
What does a return statement do in a method?
The return statement specifies the value that will be returned to the calling location.
What are static methods and how are they invoked?
Static methods are invoked through their class name without needing to create an object first.
What happens when a variable is declared as static?
Only one copy of the variable exists, shared among all objects instantiated from the class.