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.
What is the this reference in Java?
The this reference allows an object to refer to itself.
What is method decomposition?
Method decomposition is breaking down a complex problem into smaller, manageable methods.
How are parameters passed in Java methods?
Parameters are passed by value, meaning a copy of the actual parameter is stored in the formal parameter.
What is the structure of a UML class diagram?
A UML class diagram consists of class names, attributes (data), and operations (methods).
What do solid arrows represent in UML diagrams?
Solid arrows show that one class uses another by calling its methods.
What are service methods in Java?
Service methods are public methods that provide the object’s services and can be invoked by clients.
What is a support method in Java?
A support method assists a service method and should be declared with private visibility.
Fill in the blank: A _______ method is used to give values to the instance data when the object is initially created.
constructor
True or False: Instance variables exist as long as the object exists.
True