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).
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.
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.
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 (http://en.wikipedia.org/wiki/Abstraction_(computer_science) ) 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.....!
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.