Monday 28 November 2011

Working With Oops Concepts



            Based On The Style Of Programming The Languages Are Divided  Into 3 Types
  1. Procedural Languages
  2. Structural Languages
  3. Object Oriented Programming Languages

A Language Supports Oops Concept That Language Is Called As Object Oriented Programming Language.

Drawbacks With C Language:

Int Sal = 40000;
                        Printf(%D”,Sal); O/P -7233
Problem: No Boundaries For Datatypes.It Is One Drawback.

Int I = 500 * 500/500;
            Printf(“%D”,I);  O/P -27 (GARBAGE VALUE/500 =ANOTHER GARBAGE VALUE)
Problem: Difficult To Calculations

Another Problem Is No Security For The Data
 
In C Language Like These Problems Upto 400

Conclusion:
           
            To Overcome Above Problems ANSI(American National Standard Institute ) Defined A Set Of Rules Called As OOP’s Concepts In 1980.
When A Language Supports Following OOP’s Concepts Then It Is Called As Object Oriented Programming Language.
  1. Encapsulation
  2. Abstraction
  3. Polymorphism
  4. Inheritance

Encapsulation Is A Concept Of Data Binding.
Abstraction  Means  To Full Information About An Entity.
Polymorphism Means Providing Many Functionalities With A Single Name
Inheritance Is A Concept Of Deriving The Features From Parent To Child.
 In C++ By Using Friend Function We Can Access Private Data For Encapsulation

Classes And Objects
Class Is A Collection Of Fields, Properties ,Methods, Events.
Private Data Of A Class Is Called A Field
Properties Defines Shape Of An Object
What An Object Can Do Is Called As A Method
What An User Can Do With Object Is Called As A Event

Object:  Instance Of Class Is Called As Object

Syntax To Create A Class .
            Class Classname Referencetype
                        {
                                    Private Int X ,Y ;
Private String S;

                        Public Void Print( ) Method
                                    {
                                                Int I;
                                    }
                        }
Note:
  1. Classes Must Be Declared In GD
  2. VARIABLE Created With In A Class Are Called As Reference Types , Hence It Contains Default Value
  3. Variables Executed With In A Method Are Called Value Types , Hence It Doesn’t Contains Default Value


Syntax To Create An Object :

Cl-Name  Obj = New Cl-Name                      // Memory Allocation Opatator
Cl-Name X ; // Reference  ( It Is Not  An Object )

Logical Diagram Of A Class:

  1. Always Object Can Access Only Public Data ,Public Methods.
  2. Object Can’t Access Private Data.
  3. If Object Access No Security Public Methods Can Access Private Data
  4. Every Time Object Is Stored I A New Memory Location .The Adderess Is Return With Help Of Gethashcode
By Default Every Class Will Be Inherited From System.Object Class

This Keyword


         This Keyword Will Be Created At Runtime And It Is Under The Control Of CLR.
         THIS WORKS LIKE AN OBJECT FOR CURRENT CLASS
         When A Local Variable Of A Method Has The Same  Name As That Of The Instance Variable, The Local Variable Hides The Instance Variable.
         In Such Cases, "This" Can Be Used To Refer To The Instance Variables.
Class Demo
{
  Int I; // Instance Variable
  Public Void Fun (Int I)
  {
     I = 10;  // The Local Variable Is Referred
     This.I = I; // To Refer To The Instance Variable, This Is Used
  }
}

No comments:

Post a Comment