Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 29843 |  Welcome, Guest!   Register  Login
Home > Articles > OOPS > Basic Concepts of OOP: Encapsulation and Inheritence

Basic Concepts of OOP: Encapsulation and Inheritence

1 vote(s)
Rating: 5 out of 5
Article posted by ZON on 8/31/2010 | Views: 12442 | Category: OOPS | Level: Beginner | Points: 150 red flag


these are the basic concepts of Object Oriented Programming. I wrote it for those who don't have basic concepts of oop, and for those who feels programming a big monster. I tried to make them understand as much easiest as i could in my blog.. Best of Luck

Introduction


In this article i would like to describe the people what are the basic concepts of Object Oriented Programming
The OOP stands on the following three pillars.

  1. Object &Class (Encapsulation)
  2. Inheritance
  3. Polymorphism

1 Object & Class (Encapsulation): 

       

         Object:


The Object is an Instance in programming language which is made by inspiring from the real world which contains some properties and methods.

Lets take an example of a person(object) from the real world.

A person is an object, as i told you before that an object could have methodes(behaviour)& properties so here person(object) could have some properties like his black hair,fair color,tall,and so on..Simillarly it could have the methodes like Eat,Run,Play,Sleep and so on..All these properties & methodes are kept stored in a seperate class.
          

         Class:


A class is basically a container where object lies..In programming we define all the properties&methodes in a seperate class while we make object of that class in main class... It means we generate the objects from main class, lets have a look..

class cat

{

   public void eat()

         {

           console.writeline("cat eats mouse");

          }

    public void walk()

          {

            console.writeline("It walks slowly...");

          }

}

Here we have defined a class and in 'class cat' " public void eat() " and " public void walk() " are methods.now we make an object in main class and call these methods...

static void main ()

{

   cat mycat = new cat();

    mycat.eat();

    mycat.walk();

    console.readline();

}

This is the main  class in which we make an object named mycat of the classs cat.. after making the cat's class object we can call its methods&properties by writting "mycat." when we put dot after the object it calls all the methodes & properties from the related class...

Encapsulation in OOP?


Encapsulation is the word which came from the word "CAPSULE" which to put some thing in a kind of shell. In OOP we are capsuling our code not in a shell but in "Objects" & "Classes".  So it means to hide the information into objects and classes is called Encapsulation.


2 Inheritance:


The Inheritance is one of the main concepts of oop.Inheritance is just to adobe the functionality (methods & properties) of one class to another. This simple term is known as Inheritance.  

Lets have a look of code

public class cat
{
   public void eat()
   {
      console.writeline("cat can eat");
    }
   public void walk()
   {
    console.writeline("cat can walk");
   }

}

now we make another class of another cat and we inherit the methods of the first class to the new class.Do remember in programming we inherit one class to another by coding " : " colon between the parent and child class.

Lets have a look.. 

public class EgyptianCat : cat
{
  public void jump()
  {
     console.writeline("Egyptian cat can jump"); 
  }

 public void bite()
  {
    console.writeline("Egyptian cat can not bite"); 
   }
}

static void main()

{

cat mycat=new cat();

mycat.eat();

mycat.walk();

EgyptianCat yourcat=new EgyptianCat();

yourcat.eat();

yourcat.walk();

yourcat.jump();

yourcat.bite();

console.readline();

}


this is the code in main class in which we are inheriting the class EgyptianCat to the class cat, so that the new class becomes the child class of the first class which is now called the parent class.

In the next article, I shall describe about Polymorphism.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Faizan Ahmed

Experience:3 year(s)
Home page:
Member since:Tuesday, August 31, 2010
Level:Starter
Status: [Member]
Biography:This is faizan_ahmed. A graduate in Software Engineering from the University of Karachi,having an aim to change the world by my programming view.
>> Write Response - Respond to this post and get points
Related Posts

Basic Concepts of Object Oriented Programming : Polymorphism This is based on Polymorphism,in which i am trying to make Polymorphism as easy as i can for those who don't have confidence on their Concepts.. Regards : Software Engineer Faizan Ahmed

This article will discuss about Polymorphism in object oriented programming.

This article will discuss about the encapsulation in programming.

Here we will see and understand OOP's very basic but difficult to show concept of Protected, Internal and Protected Internal Access modifiers in OOPs using C# code examle.

This article will explain you about inheritance by using a suitable example for the fresher's and for the working guy's to clear the OOP's concept.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/28/2012 11:54:36 AM