Saturday, November 26, 2016

oop programming language - Define Object Oriented Programming

oop programming language - Define Object Oriented Programming

         

   What is Object Oriented Programming (OOP)


O O P is a technique or methodology which is used in development process to develop and design the program using objects and classes it provides the following concepts:
o   Object
o   Class
o   Inheritance
o   Polymorphism
o   Abstraction
o   Encapsulation
Define Object Oriented Programming

Note:

Inheritance
Polymorphism
 Abstraction and Encapsulation these are the basic pillars of OOP.


     1. Object:
Anything which has state and behavior is knows as object. Let’s understand the concepts of state and behavior.
  o   State: represents the its value means its data.
  o   Behavior: represents the its functionality
  o   Let take the example of simple object “Pen”. Pen has some data (state) like name (piano, Picasso, etc.), color (blue, black, red, etc.) and its functionality (behavior) is writing.

  o   So everything in the world represent them self as an object because they have some states and behavior.

  o   Syntax: ClassNamereferenceVariable = new  ClassName();

      2.  What is  Class in :

      Class:
There are lot of definition of class some of them are below
  o   Class is a collection of different types of objects
  o   Class is a collection of data and functions
  o   Class is a group of objects that has some common properties
  o   Class is a blueprint or template which describe the objects types.

  o   Example:
        take an example of Animal, what do you mean by animal? 
        In real world lot of animals are exists, if I take some of them like: horse, dog, cat and camel.
        Now as we know very well that every animal has own properties.
        If we take dog and cat, basically they both are animal but
       they both have different state and behavior. So, 
       now hope it’s clear the concepts of class and object.
       Animal is a class which having different types of animal objects 
       (horse, dog, cat and camel) and every objects has own states and behaviors.
  o   Class contains data members, methods, constructors, block, interfaces. 
  o   Constructors, block and interfaces you will learn in coming tutorials
  o  I’m giving a class example with data members and user defined methods.

Example:



public class BasicClassDemo{
// instance variable
int price;
string name;
// user define method to set data values
public void  set Data(int p, string n){
prince = p;
name= n;
}
// get data values
public void getData(){
system.out.println("Name: "+name);

system.out.println("Price: "price");
}
public static void main (string []args){
// class object
BasicClassDemo = new BasicClassDemo();
Demo.setData(50000, "Bike");
demo.getData();
}
}
Define Object Oriented Programming

Note: read below paragraph carefully ? Object Oriented Programming

In above example I create two methods (setData (int p, String n) and getData()) and two data members (int prince and String name). two access instance variable and method you need to create an object of that class so for this purpose I create an object with class name and its reference name is demo.Define Object Oriented Programming
               
BasicClassDemodemo = newBasicClassDemo();

Now I call user define method through the help of object reference variables like
demo.setData(50000, ”Bike”). The setData method required two arguments one is integer and second is String after, this method will set the value of instance variables, if you call instance variable before setData method it will display 0 and null because we just declare them not assign any value. After set data we call getData method this method will display the value of data members which we set through the setData method. 
Define Object Oriented Programming



No comments:

Post a Comment