0% found this document useful (0 votes)
15 views10 pages

Oop - 1

The document discusses programming concepts related to classes, encapsulation, and arrays in Java. It explains variable initialization, static variables, and method overloading, as well as the structure of classes like Payment and Course. Additionally, it covers the importance of data integrity and access control through private fields and methods.

Uploaded by

Aye Myatt Naing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views10 pages

Oop - 1

The document discusses programming concepts related to classes, encapsulation, and arrays in Java. It explains variable initialization, static variables, and method overloading, as well as the structure of classes like Payment and Course. Additionally, it covers the importance of data integrity and access control through private fields and methods.

Uploaded by

Aye Myatt Naing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

re

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

2. `static` `Payment` [2]


si
vi

Static means the variable belongs to the class, not


any specific instance .
re
3. [4]

int quantity is efficient for


storing whole numbers .

useful for textual data like


string item is
identifying
feed items .

om
4. [3]
.c
jo
`**private** FoodItem[] fi = **new** FoodItem[100]`
do

It declares an that holds up to 100


foodstem objects .
array
on

16 is
private it's accessible only within
a
array ,
so
si

class .
Payment
vi
re
5. `Payment` `addFoodItem()` `FoodItem` [3]

`addFoodItem()`

public void add food stem foodstem item)


-
i
(fidount < fi ·
length) E
filfileunt] item ;
filount j
++

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 .

between based method


The compiler distinguishes them on

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) ;

Far (int := 3 ; < numbersolength ; +E


it (numbers ( : ] < min7E
min-numbers (i) ;
3

om
.c
jo
2. [2]
do
on

It each number with the current min


compares
.
si

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;

public Course(String courseName, int courseCode, int capacity) {


this.courseName = courseName;
this.courseCode = courseCode;
this.enrolledStudents = new Student[capacity];
}

om
public void enrollStudent(Student student) {
// code to add a student to the enrolledStudents array
}
} .c
jo
public class Student {
do

private String studentID;


private String name;
on

private boolean activeStatus;


si

public Student(String studentID, String name) {


this.studentID = studentID;
vi

this.name = name;
re

this.activeStatus = true;
}

public String getStudentID() {


return studentID;
}

public void setActiveStatus(boolean status) {


this.activeStatus = status;
}
}
1. [2]

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

You might also like