Question 2a: Explain further on the three main principles of Object-Oriented Programming
SOLUTION TO THE ABOVE QUESTION
ANSWER.
I)Inheritance
Inheritance is a mechanism in which one class acquires the property of another class.
The class that acquires the properties of another class is called a sub-class or the child class
while whose properties are inherited is called the base class. For example, the relationship between person and a student, a student class can acquire some properties from the person class like name and age because every person has a name and is several years old and also a student is a person.
II)Encapsulation
Encapsulation in java is process where the internal implementation of a class
is hidden from the outside world. In java we encapsulate by making the data members of a class private. The variables of a class that are declared as private will be hidden from other classes i.e
they can not be accessed directly, they can be accessed only through the methods of their current class.
III)Polymorphism
Polymorphism in Java is the ability of an object to take many forms. Polymorphism in java allows us to perform the same action in many different ways i.e. we can perform a single task in different ways.
Comments
Leave a comment