Meaningless Drivel is fun!*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OOPS Concepts - Redefined(Confirmation required)" Watch "OOPS Concepts - Redefined(Confirmation required)" New topic
Author

OOPS Concepts - Redefined(Confirmation required)

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
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,
Ravi.
David Newton
Author
Rancher

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: 45
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,
Ravi.
Chris John
Greenhorn

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OOPS Concepts - Redefined(Confirmation required)
 
Similar Threads
4 key points about Oops
Articles on OOP
Doubts in Basic Concepts of OOPS
OOPS
An example of abstraction in java