Wednesday, May 4, 2011

Java- OOPS Concepts


Object oriented Programming Concepts:

1.Class
2.Object
3.Encapsulation
4.Abstraction
5.Polymorphism
6.Inheritance
7.Message Passing
8.Dynamic Binding

Explanation:

Class:
1) A Class is an shape and behaviour of an object.
2) It is a template for multiple objects with similar features.
3) It is a Collection of data and methods.

Example:

Class Book
{
        String name
        Public void sell()
         {
               .............
          }
}


Object:

1) Instance of a class
2) It can be used to access the variables and methods that form part
     of the class
3) Each instance of a class has its own copy of instance variables
     defined in the class and hence hold different attributes.
                     -----Attributes means 'values'-----
Example:
                         book obj1=new obj1();
                         obj1.sell();            ---> obj1 is a object

3)Encapsulation:
     
1) Encapsulation binds together data and code its manipulates.
2)Wrapping up of the data & codes 
3) Prevent the code form external users.

In simple words, the data and methods bind together with in a class.
                   ----It is also called information hiding-----

4) Abstraction:
                    Abstraction and encapsulatin having some relatonship between them.
          Encapsulation have two types:
                      1) Data Abstraction
                       2) Information hiding
    "Data abstraction"  means "focuses on outside view of an object"
                            ( To hide the actual details)
 Ex: We know about car gear only, we dont know inside process. We know only gear actions, not actual parts.
              (The actual parts are hidden form us)
   
"Information hiding" means "Prevent clients from inside view.
                        (Prevent the data from others)         

Ex:   we have only abstract function, but that fuction code is hidden form cliends. they know only method name.

5) Polymorphism:
           1) one interface, multiple forms
           2) Single entity used in many ways

Ex:  Single man, can do many works.
        In java, we have System.out.println(a);
       "a" may be integer or float or string. it is used many ways.
    
      ------ "Polymorphism used in overriding concepts"-----

6) Inheritance:
           1) Base class properties derived by sub classes.
                                          (or)
             To acquire base class properties to derived class
       In java, We havent "Multple Inheritance" instead of this one 
                   we have " Inheritance concepts"

7)Message Passing:
            One object sending message to anthor object.

  Normaly we have features to send request and get response in oops concepts.

8) Dynamic Binding:
             It is a process of mapping a message to a specific sequence of code at " runtime"
                  Dynamic means "Run time"


***********"Try to learn with real time examples."************

0 comments:

Post a Comment

RASIGATECH. Powered by Blogger.

Popular Posts

Followers