Object oriented programming


Object oriented programming

‘Object oriented programming’ is a type of programming which involves object oriented principles like encapsulation, polymorphism and inheritance. These principles are implemented by means of classes, methods, variables and other constructs in Java. We saw a sneak peek into object oriented programming in the Java 101 post. 

What is inheritance?

When classes and interfaces are subclassed, the sub-class or the sub-interface inherits the properties of the class above it. This is inheritance. Recall, that a class  defines methods and variables and is the basic building block of programs in Java. Inheritance promotes code reuse. For example,

public class Car extends Vehicle{


The above code shows that ‘Car’ class extends from ‘Vehicle’ class and inherits the properties of ‘Vehicle’. 

What is Encapsulation:

When the variables of a class are made ‘private’ and can be exclusively accessed only by its ‘public’ methods’, the class is said to exhibit the property of ‘Encapsulation’. Encapsulation ensures that the data and the methods are bound together and they can be accessed by other classes only by the classes public methods. 

What is polymorphism?

Polymorphism is the ability of the object to take on different forms. For example, if we consider a method defined as ‘Shape’ in the super class, each sub-class namely Triangle, Square, Circle will have their own implementation of ‘Shape’. Thus the object ‘Shape’ takes on different forms in different sub-classes. This is the concept of ‘Polymorphism’.

This post is for alphabet ‘O’ for the Blogchatter challenge… the previous post is here...


About the author

Jayanthi administrator

Jayanthi Manikandan has an undergraduate degree in Computer Science from India and a Master's degree in Information systems with a specialization in Information security from Detroit, MI, USA. She has written blogs for Simplilearn, Whizlabs software, InfoSec institute and Jigsaw academy. She has created e-learning videos for Whizlabs software and Twenty19. She has been passionate about Information security and has several years of experience writing on various technical topics. Additionally, she loves to pen a few personal thoughts here as well! :)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.