Professional Documents
Culture Documents
Java II - Group 8
Java II - Group 8
Oriented
Programming
Concepts
Table of content
Object-Oriented-Programming Concepts
Snippet Examples;
Run Code
Output:
I am an animal
1.iv) Public Access Modifier
When methods, variables, classes, and so on are declared public, then we can access
them from anywhere. The public access modifier has no scope restriction.
Snippet Examples;
In this case the leg count as a variable has been specified as a public
variable which could give any class access to the variable also the
method display can have ease of access due to the method being
handed by an access modifier as a public.
1.v) CONCLUSION
To conclude, access modifiers are mainly used for
encapsulation. It can help us to control what part of a program can
access the members of a class. So that misuse of data can be
prevented.
2) Encapsulation
Encapsulation is one of the four fundamental OOP concepts.
The other three are inheritance, polymorphism, and abstraction.
Encapsulation in java is a mechanism of wrapping the data
(variables)and code acting on the data (methods) together as a
single unit.
In encapsulation, the variables of a class will be hidden from
other classes, and can be accessed only through the methods of
their current class
Therefore, it is also known as data hiding
• Increase flexibility: we can make the variables of the class read-only or write-only
depending on our requirement. If we wish to make the variable read-only then we have to omit
the setter methods like setName(), setAge(), etc. from the above program or if we wish to make
the variables as write-only then we have to omit the get methods like getName(), getAge(), etc.
from the above program.
• Reusability: Encapsulation also improves the re-usability and is easy to change with new
requirements.
• Testing code is easy: Encapsulation code is easy to test for unit testing.
3) Immutable Classes and Objects
Immutable classes in java mean that once a class is created its content cannot
be changed in java.
In Java, all the wrapper classes such as Integer, Boolean, Byte, Short, and the String
class are immutable. We can create our own custom immutable class as well.
Code
continues
Java Programming II
ICT 2223
GROUP 8
Names and Matriculation Numbers
MATSASSE NOUGOUM ROXANNE FELIXIA
MBAH ALAIN AZAH
MBAKU JUNIOR JEFF
MBIA AHANDA HONORINE ELIANE
MBOH BLESS PEARL NCHONGBOH
MESSI NGANDI JOSEPH
METCHEHEH TCHOMTE ARTHUR ICTU1021292
METILA KAMGA LEATITIA
MEVOULA BAYIHA DEBORA
MEZOUOGUE MICHELLE LEANDRA