Basic concepts in Oops - 2

Hi everyone, this is the continuation of the previous post. Here i am discussing some more important concepts in oops.

6) Destructor

Destructors are invoked automatically when an object goes out of scope or when delete operation is used to destroy a dynamically created object. The method "destructor" is used in C++ to clean up an object's state. Garbage collector does the job of destroying unused objects in Java.

7) Inheritance

Inheritance is the property by which objects of one class can access the properties of other class. There are two types of inheritance - single inheritance and multiple inheritance. In single inheritance one or more class inherit from a single base class. In multiple inheritance one or more class inherits from more than one base class. Following shows an example of inheritance.


class Vehicle
{
int vehicleId;
int milage;
Vehicle(int a, int b)
{
vehicleId=a;
milage=b;
}
}

class Car extends Vehicle
{
int yearOfManufacture;
Car(int a, int b, int c)
{
super(a,b);
yearOfManufacture = c;
}
}


class MainClass
{
public static void main(String args[])
{
Class benz = new Vehicle(10,60,1990);
}
}


Here, the class Car inherits from the class Vehicle.

8) Super class or base class

Super class or base class is the class from which other classes inherits. In the above example Vehicle is the super class or base class.

9) Sub Class or Derived Class

Sub class or derived class is the class which inherits from other classes. In the above example, Car is the sub class or derived class.

10) Super()

Super() is a method used in derived class to call the base class constructor.

Hope this post gave you a clear idea of some of the topics in object oriented programming. Check my next post for more about oops. Comments/ suggestions are always welcome.

Similar posts

1) Oops - 1
2) Oops - 3
3) Oops - 4

Comments

Popular posts from this blog

Difference between "diff" and "sdiff" commands in Unix

Anonymous classes in C++