Chapter 6 Flashcards
What is an object in Java?
An object is an entity in memory that performs specific tasks. It can:
Store data (fields).
Perform operations (methods).
Name two capabilities of objects in Java.
Objects can store data (fields).
Objects can perform operations (methods).
What is a class in Java?
A class is a blueprint for creating objects. It specifies:
The data an object can hold (fields).
The actions an object can perform (methods).
What is an instance of a class?
An instance is a specific object created from a class.
Give examples of objects you’ve used in Java.
Scanner: Reads input from users.
Random: Generates random numbers.
PrintWriter: Writes data to files.
What are the fields in a Rectangle class?
length: Holds the rectangle’s length.
width: Holds the rectangle’s width.
What are the methods in a Rectangle class?
setLength: Sets the length.
setWidth: Sets the width.
getLength: Returns the length.
getWidth: Returns the width.
getArea: Calculates and returns the area (length * width).
What does UML stand for?
Unified Modeling Language. It is used to visually represent object-oriented systems.
What are access specifiers in Java?
Java keywords that control how fields or methods can be accessed.
What does the public access specifier do?
A public member can be accessed by any code, inside or outside the class.
What does the private access specifier do?
A private member can only be accessed by methods within the same class, protecting it from external access.
What is the purpose of the set and get methods in a class?
set methods assign values to fields.
get methods retrieve values from fields, ensuring controlled access.
What does an object need to perform its actions?
An object needs a class as a blueprint to define its fields and methods.
How many objects can be created from a single class?
As many as needed; each object is an independent instance of the class.
Why are access specifiers important?
They help encapsulate and protect data within a class, controlling how it can be accessed and modified.