Core JavaJava Interview Questions

Object oriented principles in Java Explained in Short

Posted On
Posted By admin

As you probably know, Java is an Object-oriented language. There are some fundamental object-oriented principles that are supported by Java. In this post, I will give you an overview of the object-oriented principles supported by Java. I will also explain how Java supports them. An understanding of these OOPs principles will give you a strong foundation while writing code.

Abstraction

Abstraction simply means hiding the internal details from the outside world. In Java, classes & methods are used to achieve abstraction. So a class hides its internal working from the outside world & only provides public methods for the functionality which the outside world needs to access.

Encapsulation

Wrapping together data & code that operates on the data together as a single unit is referred to as encapsulation. Again, a well-implemented java class can be an example of encapsulation. By well implemented, I mean that the correct access specifiers are used i.e. fields should have private access & the methods that operate on the data must have public access.

Polymorphism

Polymorphism is when one task is performed in different ways. Java supports two types of polymorphism, compile-time, and runtime. Compile-time polymorphism is achieved via method overloading. Runtime polymorphism is achieved via method overriding. Method overloading is known as Compile-time polymorphism since the version of an overloaded method to be invoked is determined at compile time. Method overriding is known as runtime polymorphism since the version of an overridden method to be invoked is determined at runtime.

Inheritance

Inheritance allows programmers to create new classes that share some of the attributes of existing classes. This lets us build on previous work without reinventing the wheel. Inheritance allows us to reuse code. The inherited object is called a superclass and the object that inherits the superclass is called a subclass.

Further Reading

Conclusion

So, in this article, we understood about the object-oriented principles in Java.

 

If you'd like to watch a detailed video tutorial of this topic or other related topics, do check out my Java course here

Also, if you'd like to test your Java knowledge, do check out my practice tests course here


If you like this post, please do let me know via the comments box below.  You can also connect with me via my Facebook Page or subscribe to my Youtube channel!

Related Post

leave a Comment