-->

Explain the terms : polymorphism/inheritance/class/object.

q)Explain the terms : polymorphism/inheritance/class/object.
ans:-

These all are features of object oriented programming.Lets know about them.

Object:-
An object can be considered a "thing" with some attributes and  can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the hand can grip something or a Student(object) can give the name or address. They all have state and behavior. like ,Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).
  For example if “customer” and “account.” are two objects in a program, then the customer object may send a message to the account object requesting for the bank balance. Each object contains data and code to manipulate the data. Objects can interact without having to know details of each other’s data or code.

Class:-
In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created. So it can be said as collection of same type of objects.


Inheritance
Inheritance is mainly used for code reusability.In the real world there are many objects that can be specialized. In OOP, a parent class can inherit its behavior and state to children classes. Inheritance means using the Predefined Code. This is very main feature of OOP, with the advantage of Inheritance we can use any code that is previously created. This concept was developed to manage generalization and specialization in OOP.  Lets say we have a class called Car and Racing Car . Then the attributes like engine no. , color of the Class car can be inherited by the class Racing Car . The class Car will be Parent class , and the class Racing Car will be the derived class or child class
The following OO terms are commonly used names given to parent and child classes in OOP:
Superclass: Parent class.
Subclass: Child class.
Base class: Parent class.
Derived class: Child class
It can have many types.
single inheritance:-one derived class inherits property from one base class
multiple              “  :- one derived class inherits property from many base classes.
multi level          “ :-in this many derived classes are inherited from many base classes
hierarchical       “ :-under this many derived classes can be inherited from single base class
hybrid                 “:-it’s a combination of hierarchical and multilevel.

Polymorphism:-
Its an important OOPs concept , Polymorphism means taking more than one forms .Polymorphism gives us the ultimate flexibility in extensibility. The ability to define more than one function with the same name is called Polymorphism.Polymorphism allows the programmer to treat derived class members just like their parent class’s members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to calls of methods of the same name .If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). Each subclass overrides the speak() method inherited from the parent class Animal.
example is
Simple example of Polymorphism, look at an Account (it may be checking or saving assuming each attract different dividends) you walk in a bank and ask a teller what is my balance? or dividends? you don't need to specify what kind of an account you're having he will internally figure out looking at his books and provide you the details.


No comments:

Post a Comment