1/32
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a class in Java?
A data type that defines what data an object can store and its behaviour (via instance methods).
What is an object?
An instantiation of a class that holds data.
What are class attributes?
Variables shared among all instances of a class.
What are instance attributes?
Variables that belong to a specific object.
What are instance methods?
Methods that define behaviour for individual objects.
What are class (static) methods?
Methods that define behaviour for the class itself and can be called without creating an object.
What is a constructor?
A special method used to initialize objects when they are created.
What must a constructor have?
The same name as the class and no return type.
When are constructors called?
Automatically when using new
, or within another constructor of the same class.
What does the this
keyword do in a constructor?
Refers to the current object and is used to resolve naming conflicts.
What is constructor overloading?
Defining multiple constructors with the same name but different parameter lists.
Why use constructor overloading?
To allow object creation with different levels of information.
What is constructor chaining?
Calling one constructor from another within the same class using this()
.
Where must this()
appear in a constructor?
It must be the first line.
What happens when a method or constructor is called?
An activation record (stack frame) is pushed onto the call stack.
What happens when the method ends?
The stack frame is popped and local variables are discarded.
What does LIFO mean?
Last In, First Out — like a stack of plates.
What is stored in an activation record?
Local variables and JVM-related info for method execution.
What are static variables and methods?
Class-level fields and methods shared across all objects.
Can you access static members without creating an object?
Yes
What does final
do?
It marks variables as constants — their values cannot be changed.
Do static variables exist if no objects are created?
Yes
What is encapsulation?
Combining state and behaviour in a class and restricting direct access to internal data.
What is information hiding?
Preventing direct access to attributes using private
and exposing them through methods.
What are getters and setters used for?
Getters read private variables; setters modify them.
What is method chaining?
Calling multiple methods on the same object in a single line.
What is required for method chaining to work?
Each method must return this
(the current object).
What are Java packages used for?
To group related classes and interfaces in a structured way.
What is the default package?
The unnamed package used when no package is declared.
What does public
mean?
Accessible from anywhere.
What does private
mean?
Accessible only inside the class.
What does the default (no modifier) mean?
Accessible within the same class and package.
What does final
mean for variables?
The variable cannot be changed after it is assigned.