Class and Objects Flashcards

(86 cards)

1
Q

A high level, powerful programming language that uses the ___________________ ______________ approach

A

Object-oriented Programming(OOP)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A programming style that models _________________ as “objects”

A

real-world entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Data ( ____ ): information or attributes

A

fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Object have: (2)

A
  1. data
  2. Behavior
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Behavior( _____ ) : Actions or functions

A

methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Programs are written as _______________________ or functions.

A

step-by-step instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Programs are written as step-by-step instructions or _____________.

A

functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Focuses on ________ performed on ____.

A
  1. operations
  2. data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Becomes hard to manage as programs _______ and ________.

A

grow larger and more complex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

OOP:

Organized code into ________.

A

reusable objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Object-Oriented Programming:
Makes software development: ?

A

More structured.
Easier to scale.
Simpler to maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why Use OOP in Java?

A

Code Reusability
Easier Maintenance
Better Security
Real-World Modeling
Java’s Popularity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Code Reusability:
Write code once and reuse it multiple times, saving _____ and_____.

A

time
effort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Easier Maintenance:
______ is organized into______, making it simpler to debug and update.

A

Code
objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Better Security:
_______ keeps data safe from _______ or _________.

A

Encapsulation
unintended access
modification

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Real-World Modeling:
______mirrors how________, making it ________ and practical.

A

OOP
objects interact in real life
intuitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A _________ is like a blueprint or template for creating objects.

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A class is like a ______________ or template for creating objects.

A

blueprint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

A class is like a blueprint or __________ for creating objects.

A

template

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

A class is like a blueprint or template for ____________.

A

creating objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

A class is like a blueprint or template for creating objects.
It defines:
_____________: Information about the object.
___________: Actions the object can perform.

A

Data (fields/attributes)
Behavior (methods)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Analogy:
Think of a class as a ________ for baking a cake.
The ____________ (data) and ______ (methods).
The _________ (objects) are created using the recipe, each with unique variations (e.g., flavors, decorations).

A

recipe
recipe lists ingredients
steps
actual cakes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Variables in a Class:

A

Instance Variables:
Class Variables:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Instance Variables:
Declared inside a class but outside any method.
_______ and unique to each object.

A

Non-static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Class Variables: Declared with the______________. Shared across all objects of the class.
static keyword
25
What is an Object? An object is a _____________ created from a class. If a class is a blueprint, an object is the __________made from that blueprint.
real-world entity actual product
26
____________: The process of creating an object from a class.
Instantiation
27
__________ are the characteristics or properties of an object.
Attributes
28
Attributes are the ____________________ of an object.
characteristics or properties
29
___________ are specific to an object and can only be accessed within that object.
Instance variables
30
What are Attributes? Attributes are the characteristics or properties of an object. They store ________ that defines what an ______ is. Declared inside a class but outside methods. Have data types like int, String, double, etc. Also called ______________. They belong to a_________. Each object has its own copy of instance variables.
data object fields or instance variables class
31
Java reserves ______ for the object based on the class blueprint.
memory
32
___________ → The name of the class.
ClassName
33
______________ → The name of the object (instance).
objectName
34
________ → This keyword allocates memory for the object.
new
35
__________ → Calls the class constructor to initialize the object.
ClassName()
36
What is a Constructor? A ______________ used to initialize objects when they are created. It has the same name as the class and runs automatically during object instantiation.
special method
37
What is a Constructor? A special method used to initialize objects when they are created. It has the same name as the class and runs automatically during ___________.
object instantiation
38
a constructor _____________ for every object you create.
sets up initial values
39
__________________ Assigns default values to object attributes. Use when all objects should have the same default values.
Default Constructor (No Parameters)
40
___________________ Allows assigning custom values when creating an object Requires input values. Assigns custom values. Use when you want different values for each object.
Constructor with Parameters
41
Constructor with Parameters Allows assigning custom values when creating an object Requires __________. Assigns _____________. Use when you want _______________________.
input values custom values different values for each object
42
What is "this"? A _______________ in Java that refers to the current instance of a class. Helps differentiate between instance variables and parameters when they have the same name.
special keyword
43
What is "this"? A special keyword in Java that refers to the____________ of a__________. Helps differentiate between__________________ when they have the same name.
current instance class instance variables and parameters
44
Why Use "this"? Avoids _________ between instance variables and method/constructor parameters. Allows one__________ to call another constructor in the same class (constructor chaining). Can be used to _____________.
confusion constructor return the current object
45
When Do We Need "this"? Most common use is when a ___________has a parameter with the same name as an instance variable.
constructor or method
46
Problems in the Initial Constructor _________________: Default values ("Unknown Product" and 0.0f) are assigned multiple times. ___________________: Some constructors don't initialize both attributes, leading to potential issues. __________________: Values are assigned manually instead of reusing logic from other constructors.
Code Duplication Inconsistent Initialization Lack of Constructor Chaining
47
Benefits of Using this: ___________: Clearly __________ between instance variables and parameters with the same name.
Avoids Confusion distinguishes
48
Benefits of Using this: Avoids Confusion: Clearly distinguishes between instance variables and parameters with the same name. _____________: Allows one __________ to call another, reducing code duplication and __________ ______.
Constructor Chaining constructor improving maintainability
49
What are Object Methods? Also called __________, these are__________ that belong to a specific object. They define the _________ of an object, allowing it to perform actions, update values, or retrieve information.
instance methods functions behavior
50
They define the behavior of an object, allowing it to perform ______,_____________, or______________.
actions update values retrieve information
51
What is Encapsulation? One of the four main principles of _________________ (OOP). Hides the ____________ of how an object works and allows access ____________________. Analogy: Like a medicine capsule-you can take the medicine, but you can't see the ingredients inside.
Object-Oriented Programming internal details only to necessary information
52
Why is Encapsulation Important? ____________: Prevents direct modification of sensitive variables. ____________: Restricts access to certain parts of an object. _______________: Allows controlled modification of values through methods. _____________: Prevents unintended changes in the program.
Protects Data Improves Security Increases Flexibility Easier Maintenance
53
__________: Variables or methods can only be accessed within the same class.
Private Access
54
Private Access: _____________ can only be accessed within the same class.
Variables or methods
55
Why Use Private Access? Prevents direct ____________ of important variables. Protects _______from unauthorized access. Improves ___________ by restricting how data is changed. Encourages __________ through methods.
modification data security controlled access
56
__________: Retrieves the value of a private variable.
Accessor (Getter)
57
Accessor (Getter): Retrieves the ________ of a ____________.
value private variable
58
_________: Modifies the value of a private variable with validation.
Mutator (Setter)
59
Mutator (Setter): ______ the value of a private variable with _______.
Modifies validation
60
Why Are Getters and Setters Important? ___________: Variables cannot be accessed directly. _____________: Setters validate before updating variables. ______________: Only allowed methods can modify data.
Protects Private Data Ensures Valid Values Provides Controlled Access
61
What is Method Overloading (Method Overloading)? Allows a class to have _________ with the same name but different parameter lists. The ___________ is called based on the ________ passed during execution.
multiple methods correct method arguments
62
Why Use Method Overloading? ___________: Reuses method names for similar actions. _____________: Keeps related actions under the same method name. ___________: Allows calling a method with different input types or counts.
Reduces Code Duplication Improves Readability Provides Flexibility
63
Reduces Code Duplication: ____________ for similar actions.
Reuses method names
64
Improves Readability: Keeps related _______ under the ___________.
actions same method name
65
Provides Flexibility: Allows__________ with __________input types or counts.
calling a method different
66
_______________ form the foundation of _______________ in Java, enabling developers to model real-world entities in a structured and reusable way.
Classes and objects Object-Oriented Programming (OOP)
67
Classes and objects form the foundation of Object-Oriented Programming (OOP) in Java, enabling developers to model _________ in a structured and ___________.
real-world entities reusable way
68
A ______ acts as a ____________, defining the attributes (data) and methods (behavior) that describe what an object is and what it can do.
class blueprint or template
69
A class acts as a blueprint or template, defining the _____________ and ___________ that describe what an object is and what it can do.
attributes (data) methods (behavior)
70
This promotes code __________ and__________. On the other hand, an object is an instance of a class, representing a real-world entity with its own state (data) and behavior (methods).
reusability organization
71
______ allow developers to create _____ and ______________ by encapsulating data and functionality into self-contained units.
Objects modular scalable applications
72
Objects allow developers to create modular and scalable applications by ___________ and ___________ into self-contained units.
encapsulating data functionality
73
__________ is a key principle in OOP, ensuring that the internal details of an object are hidden and protected.
Encapsulation
74
Encapsulation is a key principle in OOP, ensuring that the __________ of an object are hidden and protected.
internal details
75
Encapsulation is a key principle in OOP, ensuring that the internal details of an object are ________ and __________.
hidden protected
76
By using private access and getter/setter methods, encapsulation safeguards data and provides controlled access, enhancing ________________.
security and flexibility
77
_________ play a vital role in initializing objects, setting initial values for attributes, and supporting overloading to handle different initialization scenarios.
Constructors
78
________ define the behavior of objects and can be overloaded to perform similar actions with different inputs, improving code readability and reducing duplication.
Methods
79
Methods define the__________ and can be overloaded to perform similar actions with different inputs, improving code readability and reducing duplication.
behavior of objects
80
Methods define the behavior of objects and can be __________ to perform similar actions with different inputs, improving code readability and reducing duplication.
overloaded
81
Methods define the behavior of objects and can be overloaded to perform similar actions with different inputs,____________ and ____________.
improving code readability reducing duplication
82
The _________ is another essential feature, referring to the current instance of a class. It helps differentiate between instance variables and parameters, enabling constructor chaining for efficient code reuse. Additionally, understanding the distinction between static and non-static members is crucial.
this keyword
83
The this keyword is another essential feature, referring to the __________. It helps differentiate between instance variables and parameters, enabling constructor chaining for efficient code reuse. Additionally, understanding the distinction between static and non-static members is crucial.
current instance of a class
84
__________belong to the class and are shared across all objects, while _____________ belong to individual objects.
Static members non-static members
85
____________ are essential for breaking down complex problems into smaller, manageable parts, promoting modularity, reusability, and maintainability.
Classes and objects