OOP class

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/85

encourage image

There's no tags or description

Looks like no tags are added yet.

86 Terms

1
New cards
What is a class?
A blueprint/type that defines the structure and behavior of objects.
2
New cards
What is an object?
An individual instance created from a class at runtime.
3
New cards
What do fields represent?
An object's state/data.
4
New cards
What do methods represent?
An object's behavior/actions.
5
New cards
What is a constructor used for?
To initialize a newly created object's initial state.
6
New cards
What are the key constructor rules?
Same name as the class; no return type; can accept parameters; runs during object creation.
7
New cards
How do you create a new Student object?
Student s = new Student(...);
8
New cards
What is encapsulation?
Combining related state and behavior while limiting direct access to the internal representation.
9
New cards
Why are fields often private?
To protect object state and control changes through a public interface.
10
New cards
What does a getter do?
Returns/reads a value without exposing how it is stored.
11
New cards
What does a setter do?
Accepts a new value and can validate, reject, or transform it before changing state.
12
New cards
What does this refer to?
The current object inside an instance method or constructor.
13
New cards
In this.name = name, what is this.name?
The object's field.
14
New cards
In this.name = name, what is name?
The parameter/local value.
15
New cards
What can this(...) do?
Invoke another constructor in the same class.
16
New cards
What does static mean?
The member belongs to the class rather than an individual object and is shared at class level.
17
New cards
Instance member vs static member?
Instance: belongs to each object. Static: belongs to/is shared by the class.
18
New cards
What can public members be accessed from?
Class, package, subclasses, and anywhere.
19
New cards
What can protected members be accessed from?
The class, same package, and subclasses.
20
New cards
What does no access modifier mean?
Package-private: accessible in the class and same package only.
21
New cards
What can private members be accessed from?
The declaring class only.
22
New cards
What is association?
A relationship where one object knows about or collaborates with another.
23
New cards
What is a has-a relationship?
Composition/association: a class contains or uses another object.
24
New cards
What is an is-a relationship?
Specialization/inheritance: one class is a specialized form of another.
25
New cards
Car has an Engine: has-a or is-a?
Has-a.
26
New cards
GraduateStudent is a Student: has-a or is-a?
Is-a.
27
New cards
When analyzing a problem, what do nouns often suggest?
Candidate classes/entities or attributes.
28
New cards
When analyzing a problem, what do verbs often suggest?
Behaviors/methods and responsibilities.
29
New cards
What are attributes?
What an object knows, such as name, id, status, or price.
30
New cards
What are behaviors?
What an object does, such as enroll(), calculateTotal(), or activate().
31
New cards
What are responsibilities?
What an object owns or is responsible for, such as validating state or coordinating its behavior.
32
New cards
What are the three compartments of a basic UML class box?
Class name; attributes; methods/operations.
33
New cards
What does + mean in UML?
public
34
New cards
What does - mean in UML?
private
35
New cards
What does # mean in UML?
protected
36
New cards
What does ~ mean in UML?
package access
37
New cards
What does UML multiplicity 1 mean?
Exactly one object participates.
38
New cards
What does UML multiplicity 0..1 mean?
Optional: zero or one object.
39
New cards
What does UML multiplicity 0..* mean?
Zero or many objects.
40
New cards
What is the goal of good object-oriented design?
Clear responsibilities and useful relationships among interacting, encapsulated classes.
41
New cards
What is inheritance?
Class reuse and specialization: a subclass inherits accessible state/behavior from a superclass and can add specialized behavior.
42
New cards
What is a superclass?
The parent/base, more general class.
43
New cards
What is a subclass?
The child/derived, more specific class.
44
New cards
What keyword establishes class inheritance in Java?
extends
45
New cards
What kind of relationship should inheritance represent?
An is-a relationship.
46
New cards
Are constructors inherited?
No.
47
New cards
Are private superclass members directly accessible from a subclass?
No.
48
New cards
What is method overriding?
A subclass supplies a specialized implementation of an inherited method.
49
New cards
What must match when overriding a method?
The method name and parameter types/signature; return type must match or be covariant.
50
New cards
Can an overriding method reduce access?
No; it cannot be more restrictive.
51
New cards
Is a private superclass method overridden?
No.
52
New cards
Are static methods overridden?
No. Static methods are hidden, not overridden.
53
New cards
Can a final method be overridden?
No.
54
New cards
Why use @Override?
To catch signature mistakes early and mark the intent to override.
55
New cards
Overriding vs overloading?
Overriding: subclass specializes inherited method, runtime. Overloading: same method name with different parameter lists, compile time.
56
New cards
What does super(...) do?
Calls a superclass constructor.
57
New cards
Where must super(...) appear in a subclass constructor?
As the first statement.
58
New cards
What does super.method() do?
Calls the superclass version of a method.
59
New cards
What is constructor chaining order?
Superclass initialization first, then subclass initialization.
60
New cards
What is polymorphism?
One reference type can work with objects of different concrete types/forms.
61
New cards
What is compile-time polymorphism in this module?
Method overloading.
62
New cards
What is runtime polymorphism in this module?
Method overriding.
63
New cards
What is dynamic method dispatch?
At runtime, Java selects an overridden instance method based on the actual object, not just the reference type.
64
New cards
In Shape s = new Circle(), what is the reference type?
Shape.
65
New cards
In Shape s = new Circle(), what is the actual object type?
Circle.
66
New cards
What does the reference type control in a polymorphic reference?
Which members are visible/can be called directly at compile time.
67
New cards
What does the actual object control in a polymorphic reference?
Which overridden instance-method implementation runs at runtime.
68
New cards
What is upcasting?
Assigning a subclass object to a superclass reference, e.g. Shape s = new Circle();
69
New cards
What is abstraction?
Exposing essential behavior while hiding implementation details.
70
New cards
What is an abstract class?
An incomplete base type that cannot be instantiated directly.
71
New cards
Can an abstract class contain concrete fields, constructors, and concrete methods?
Yes. It can also contain abstract methods.
72
New cards
What is an abstract method?
A method that declares required behavior without providing an implementation/body.
73
New cards
How does an abstract method declaration end?
With a semicolon, e.g. abstract double area();
74
New cards
What must a concrete subclass do with required abstract behavior?
Provide an implementation of the abstract method.
75
New cards
What is an interface?
A contract that implementing classes agree to fulfill; it focuses on required capabilities.
76
New cards
What keyword does a class use to fulfill an interface?
implements
77
New cards
Can a Java class implement multiple interfaces?
Yes.
78
New cards
Abstract class vs interface: primary role?
Abstract class: shared base type + partial implementation. Interface: shared capability/contract.
79
New cards
Abstract class vs interface: constructors?
Abstract class can have constructors; an interface has no constructors.
80
New cards
Abstract class vs interface: inheritance count?
A class extends one class but can implement multiple interfaces.
81
New cards
When is an abstract class a better fit?
For closely related classes sharing state and/or partial implementation.
82
New cards
When is an interface a better fit?
For cross-cutting capabilities/contracts that different classes can implement.
83
New cards
Why is inheritance for a has-a relationship a design mistake?
Inheritance should model is-a specialization; has-a is better modeled with association/composition.
84
New cards
Why can deep inheritance hierarchies be a problem?
More levels do not automatically improve reuse and can make the design harder to understand/maintain.
85
New cards
What may large instanceof/type-checking chains suggest?
Weak abstraction; polymorphism may be more appropriate.
86
New cards
What can empty overridden methods suggest?
The superclass may be asking subclasses to do too much.