Polymorphism (Overloading)
Polymorphism { Overloading } means simply, same methods makes different jobs in different objects.Like how ?
Let’s say we are writing java code and we are using JCheckBox ,JTextField and JButton components.When we try to use setText method for all of them the response suppose to be same,but checkbox writes the text near to checkbox icon ,textfield writes to text into itself and button object writes to text on the button.It shows us the polymorphism because same method worked different for different object.This property called polymorphism or overloading.
There is a code below the page.It is written in c++ and it is the simple example for polymorphism and inheritance.
-
-
#include <stdio.h>
-
#include <string.h>
-
#include <iostream>
-
"tried to clean but not success\n"<<endl; } // Polymorph method (virtual)
-
"room burned \n"<<endl; }
-
};
-
-
class living : public room{ //inherit to room it means it has a same properties of room
-
"living room cleaned ! \n"<<endl; //clean method is used polymorph in here
-
}
-
-
class bed : public room{
-
//something about bedroom
-
};
-
-
main()
-
{
-
room *xroom;
-
-
xroom = new bed; //created an object from bed
-
xroom->clean(); //it should say tried to clean but not success
-
-
delete xroom; // free your mind 🙂
-
-
xroom = new living; // living object
-
xroom->clean(); //it should say living room cleaned!
it’s output in the picture.
1 Comment to Polymorphism (Overloading)
Tags
Recent Posts
- PriveMall Davetiye
- Polymorphism (Overloading)
- Nautilus ve Ssh Bağlantısı
- Highlighting Nano
- Difference between C++ Class and C struct
- Gcc 4.3 and Header issues
- Re-Enable restarting X server with Ctrl+Alt+Backspace in Jaunty
- I Installed BETTER
- Ruby’de Sayiyi Yaziya Ceviren Program
- Ubuntu Volume Wheel Problem [ Fix ]
- Google Android
- Encoding mysql dump file while importing from console
- Ubuntu altinda mp3 kesmek {Cutting mp3 files over ubuntu}
- Flv’den mp3 elde eden bash programi {Converting flv to mp3}
- Video Sitelerinden İçerik İndirmek ve Videolardan Ses Almak
Hi, nice posts there 🙂 thank’s concerning the gripping information