aspose file tools
The moose likes Beginning Java and the fly likes OOPS Concepts - Redefined(Confirmation required) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OOPS Concepts - Redefined(Confirmation required)" Watch "OOPS Concepts - Redefined(Confirmation required)" New topic

OOPS Concepts - Redefined(Confirmation required)

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 48
Hi All,

I am back again with some Java basic stuff.

First of all my sincere apologies, if there are any mistakes in my post.

Please give your valuable inputs on these thread, by going thru each and every line of it with proper explanation.

Please dont give any references to another thread, as I feel no other thread is clear and complete about these concepts. So I want this thread to end the discussion on the basic concepts of OOPS(in Java).

The OOPS concepts in java are

1. Abstraction (Many books don’t discuss about this)
2. Encapsulation
3. Inheritance
4. Polymorphism

1. Abstraction :: Hiding the implementation details
In Java, we achieve this with the help of a class.

Real time example :: a car or a TV remote etc.
When we start a car, we are least bothered about the internal functionality what makes the car to start.
The same way, when we are using the power button or another buttons on a TV remote, we are not bothered how the actual functionality is happening with the help of circuits inside it.

Java example :: a class
Consider we create a Car class and it have the behavior speed(), color() etc. For any object which uses these methods are lease bothered the implementation of these methods and they just care about the functionality.

2. Encapsulation :: Hiding the data
In Java, we achieve this with the help of access modifiers.

Real time example :: Medical capsule
One drug is stored in bottom layer and another drug is stored in Upper layer these two layers are combined in single capsule.

Java example :: data (fields) in a class are marked as private and we use public methods to access these data(fields).

** By seeing the above two definitions, we can say that ‘Abstraction’ and ‘Encapsulation’ are two separate topics. Abstraction means ‘hiding implementation details’ and Encapsulation means ‘hiding the data’.**

**This concept of abstraction is no where related to abstract class or interface. When I am talking about abstraction means it’s different from abstract class. (Please clarify on this clearly)**

3.Inheritance :: using the methods of a (super)class in another (sub)class.

In Java, we achieve this with the help of sub classing (i.e using extends keyword).

Real time example :: Father and a son

Java example ::

Inheritance allows a class to be a subclass of a superclass, and thereby inherit public and protected variables and methods of the superclass.

4. Polymorphism :: many forms. A single method(name) is functioning differently.

In Java, we achieve this with the help of overriding and Interfaces. And not because of overloading, as overloading is just a different method that happens to have the same method name.
Overloading has nothing to do with inheritance and polymorphism.

Real time example :: A person, acts like a husband at home, acts like a employee at office, Good citizen in public.

Java example ::

Thanks & Regards,
David Newton

Joined: Sep 29, 2008
Posts: 12617

So I want this thread to end the discussion on the basic concepts of OOPS(in Java).

*Books* have been written on the subject--a single thread is unlikely to end the discussion.

Please UseCodeTags. Unformatted code/config/etc. is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.
Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 48
Hi David,

As you suggested, I have done the necessary modifications.

And as you said, I do agree books are written on these subjects. But, I want it to be a quick reference thats it.

Thanks & Regards,
Chris John

Joined: Sep 19, 2009
Posts: 7

Your post isn't justifying your heading as you haven't even touched anything outside the obvious. As David sadi this isn't anything you can finish of in a thread. Also since if you re gonna write a book in this thread it not going to be apt, start a blog instead.
Girish Velivela

Joined: Oct 29, 2014
Posts: 9
Hi Bhairava Surya,
I am also with Abstraction and Encapsulation. But after reading your post I got some idea about those topics.

But I four doubts.

1) we are using printf in C. Is it abstraction?
2) when I went through Wikipedia of abstraction ( ) there is some thing like data abstraction.
3) Few blogs says that 100%abstraction can be achieved in java by Interface.
4) Last one Encapsulation is nothing but 'class'.

Please give me conclusion about those three points.
thanks in advance.....!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14666

Abstractions are everywhere. Not just in programming, but in many other things in life.

There are layers of abstraction. Each layer hides what the layer below it is doing exactly. We need these layers of abstraction so that we can forget about the details of lower levels. Ofcourse, printf in C is also an abstraction. You only want to know that printf is going to print the value that you pass to it. Below your simple function call, it's going to call the operating system. The operating system is going to do lots of other calls, to write the pixels into the memory of your video card in a particular pattern so that you see letters on the screen. The CPU and the video card are going to execute machine language instructions to make this pattern happen in video memory. Going even deeper, the CPU and the video card consist of integrated circuits (computer chips) containing transistors, that are going to switch in specific patterns to make it all happen. And you can go even further down - those transistors work because they are built out of semiconductor materials which have specific properties to let electrons flow in certain ways.

Those are all levels of abstraction. Fortunately you don't have to know anything about fundamental physical particles such as electrons, about material science, about electronic circuits, about machine language, building operating systems etc. to be able to use the printf function. And that's because there are many layers of abstraction stacked on top of each other which make it so that you only have to pay attention to the highest level layer.

When you work on a software development project, you build layers of abstraction yourself. The Java programming language itself only offers you a handful of simple data types, such as integers, floating-point numbers and booleans. You use these to create classes that represent meaningful chunks of data, with methods to work on that data. Then, with a collection of classes, you build modules. And you combine a number of modules into a complete program.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41573
A class is an abstraction in the sense that it provides spaces to insert your dataNow your Car class abstracts speed; you know it has a speed but at the moment it is not known how fast it is going.
Ashwin Rao
Ranch Hand

Joined: Oct 21, 2014
Posts: 71

I just wrote a post on this topic at:

It's written in a very simple way and all concepts are explained through real-world examples so it's very easy to understand.
Give it a read and let me know if it helped!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41573
I found it a confusing read, I am afraid.
Girish Velivela

Joined: Oct 29, 2014
Posts: 9
hi @Jesper de Jong,

That was a nice explanation about abstraction. I loved it.
please help me in remain three doubts that I posted.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: OOPS Concepts - Redefined(Confirmation required)