Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

oops concept  RSS feed

 
narender sunkam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to java.
I have question like what is enapsulation,inheritence,polymorphism.
could any body explain me with a good example and defination.

thanks and regards.
 
vivekkumar sharma
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Have a look @
http://www.javaranch.com/campfire.jsp
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encapsulation is the equivalent of data hiding. You protect your instance variables (your data), and control access through setter and getter methods. You also mark instance variables as being private. In Java, we don't expose our privates.

Inheritance is a mechanism used to represent an is-a relationship between objects. So, a Square is-a special Rectangle, and a Rectangle is-a special type of Shape, and a Shape is-a type of Object.

Polymorphism says any time you need an object, and instance of that object, or instance of a more specific type will do. So, if I need a Shape, a square will do. If I need a Rectangle, a Rectangle or a Square will do. Note that polymorphism is unidirectional, so if you need a Shape, a Rectangle will do, but if you need a Square, a rectangle will not suffice.

Those are very brief answers to a very broad set of questions.

Cheers!

-Cameron McKenzie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!