Oop - 1
Oop - 1
vi
si
on
do
jo
.c
om
`Payment`
`FoodItem` `DrinkItem`
`Payment`
100
om
.c
jo
do
x
on
si
vi
re
1. [2]
om
You can initialise the variables directly when
declared This removes the .c
need to
they are
.
jo
the constructor
explicitly set them in
do
on
om
4. [3]
.c
jo
`**private** FoodItem[] fi = **new** FoodItem[100]`
do
16 is
private it's accessible only within
a
array ,
so
si
class .
Payment
vi
re
5. `Payment` `addFoodItem()` `FoodItem` [3]
`addFoodItem()`
Belse E
System, out printin /"Cannot add
, more feed items .
Array is
full "D
om
.
;
3
3 .c
jo
do
on
si
vi
re
1. `Arrival` `compareWith` [2]
`compareWith`
with the
method everleading allow multiple methods
names but
same different parameter types or numbers .
signature .
2. [2]
om
fields marked as private so it cannot be accessed
are
modification
.c controlled ,
directly. Access and are
reducing
jo
of unintended changes
do
>
-
he risk
on
si
3. [1]
vi
re
Encapsulation
1. [4]
int min
:
numbers (0) ;
om
.c
jo
2. [2]
do
on
If a smaller value is
found ,
min is updated
vi
re
3. [2]
method and
is
A local variable is declared inside a only
accessible within that method ,
private String courseName;
private int courseCode;
private Student[] enrolledStudents;
om
public void enrollStudent(Student student) {
// code to add a student to the enrolledStudents array
}
} .c
jo
public class Student {
do
this.name = name;
re
this.activeStatus = true;
}
Student student :
new Student ("S32345" , "John Doe") ;
2. `setActiveStatus` [2]
Allow the
program
to
change student's status
om
.c
jo
do
3. [3]
on
has
multiple students TheCourse class
Each Course .
si
holds Student
objects showing one to many
vi
an of a
array ,
re
relationship .
4. [2]
Ensures data
integrity by preventing direct modification
the
from outside class .
om
.c
jo
do
on
si
vi
re