zuai-logo
  • Home

  • Mock Exam

  • Cliffs

  • Study Set

  • Talk to ZuAI

  • Request a Feature

zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion Bank

What are the differences between instance and local variables?

Instance variables: belong to the object, exist throughout the object's lifetime. Local variables: exist only within the method they are defined in.

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What are the differences between instance and local variables?
Instance variables: belong to the object, exist throughout the object's lifetime. Local variables: exist only within the method they are defined in.
What are the differences between a constructor and a method?
Constructor: initializes object state, has same name as class, no return type. Method: performs an action, has a return type (or void), can have any name.
What are the differences between a default constructor and a parameterized constructor?
Default constructor: no arguments, initializes with default values. Parameterized constructor: takes arguments, initializes with provided values.
What is a class?
Blueprint for creating objects; defines state and behavior.
What is an object?
An instance of a class with its own unique state.
What are instance variables?
Attributes that define the state of an object.
What are constructors?
Special methods used to create objects and initialize instance variables.
What are constructor parameters?
Local variables that receive values when a new object is created.
What are local variables?
Variables that exist only within the method they are defined in.
What is a default constructor?
Constructor provided by Java if you don't define one; initializes instance variables to default values.
What is the state of an object?
The set of values of its instance variables at a given time.
What does 'private' mean in the context of instance variables?
Accessible only within the class itself.
What is a mutable object?
An object whose state can be changed after it is created.
What is the purpose of a constructor?
To initialize the state of an object when it is created.
Why are instance variables often declared as private?
To encapsulate the data and control access to it.
What happens if you don't define a constructor in a class?
Java provides a default constructor.
Why is it important to make a copy of a mutable object in a constructor?
To avoid unintended changes to the original object's state.
What is the significance of the 'new' keyword?
It is used to create a new object of a class and calls the constructor.
What is the return type of a constructor?
Constructors do not have a return type (not even void).
What is the scope of instance variables?
Instance variables are accessible throughout the object's lifetime.
What is the scope of local variables?
Local variables are only accessible within the method in which they are defined.
How are classes and objects related?
A class is a blueprint, and an object is an instance of that blueprint.
Why are constructors important for object-oriented programming?
They ensure that objects are properly initialized before they are used, maintaining data integrity.