Chapter 2b: OOP-I-Objects

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

33 Terms

1
New cards

What is a class in Java?

A data type that defines what data an object can store and its behaviour (via instance methods).

2
New cards

What is an object?

An instantiation of a class that holds data.

3
New cards

What are class attributes?

Variables shared among all instances of a class.

4
New cards

What are instance attributes?

Variables that belong to a specific object.

5
New cards

What are instance methods?

Methods that define behaviour for individual objects.

6
New cards

What are class (static) methods?

Methods that define behaviour for the class itself and can be called without creating an object.

7
New cards

What is a constructor?

A special method used to initialize objects when they are created.

8
New cards

What must a constructor have?

The same name as the class and no return type.

9
New cards

When are constructors called?

Automatically when using new, or within another constructor of the same class.

10
New cards

What does the this keyword do in a constructor?

Refers to the current object and is used to resolve naming conflicts.

11
New cards

What is constructor overloading?

Defining multiple constructors with the same name but different parameter lists.

12
New cards

Why use constructor overloading?

To allow object creation with different levels of information.

13
New cards

What is constructor chaining?

Calling one constructor from another within the same class using this().

14
New cards

Where must this() appear in a constructor?

It must be the first line.

15
New cards

What happens when a method or constructor is called?

An activation record (stack frame) is pushed onto the call stack.

16
New cards

What happens when the method ends?

The stack frame is popped and local variables are discarded.

17
New cards

What does LIFO mean?

Last In, First Out — like a stack of plates.

18
New cards

What is stored in an activation record?

Local variables and JVM-related info for method execution.

19
New cards

What are static variables and methods?

Class-level fields and methods shared across all objects.

20
New cards

Can you access static members without creating an object?

Yes

21
New cards

What does final do?

It marks variables as constants — their values cannot be changed.

22
New cards

Do static variables exist if no objects are created?

Yes

23
New cards

What is encapsulation?

Combining state and behaviour in a class and restricting direct access to internal data.

24
New cards

What is information hiding?

Preventing direct access to attributes using private and exposing them through methods.

25
New cards

What are getters and setters used for?

Getters read private variables; setters modify them.

26
New cards

What is method chaining?

Calling multiple methods on the same object in a single line.

27
New cards

What is required for method chaining to work?

Each method must return this (the current object).

28
New cards

What are Java packages used for?

To group related classes and interfaces in a structured way.

29
New cards

What is the default package?

The unnamed package used when no package is declared.

30
New cards

What does public mean?

Accessible from anywhere.

31
New cards

What does private mean?

Accessible only inside the class.

32
New cards

What does the default (no modifier) mean?

Accessible within the same class and package.

33
New cards

What does final mean for variables?

The variable cannot be changed after it is assigned.