English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2006-11-12 22:24:38 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

thats a concept of object orientation.
Basically in OOP based languages, you can inherit code from a parent class into a base class.
You can use that code as it is, or you can override it.
Assume there is a parent class called Animal. It has two methods
run() {
//write some run code
}
speak() {
print "Animal noises!";
}
Now assume you create a class called Dog that extends Animal. It automatically gets the run and the speak method from Animal. However it can over-ride the speak method thus
speak() {
print "BARK!";
}
So the speak method got overridden in Dog

2006-11-12 22:50:46 · answer #1 · answered by Neil 5 · 0 0

Overriding refers to hiding using the same function signature. Create a derived class function, which is similar in signature with the base class one.

2006-11-13 06:48:19 · answer #2 · answered by Vaibhav 4 · 0 0

Override functions are those which have same name but different kind or number of parameters. for example you declare a function to covert a real or integer number to string. Because Integer & Real numbers are of different types, you cannot declare one function for that. so you have to declare 2 functions with the same name and different types of parameters. Declarations might be like this:

function NumToStr(r: real):string;
begin
...
end;

function NumToStr(i: integer):string; override;
begin
...
end;

Now if you use the function with a real parameter, the first function is called, and if it's used with an integer number, the second one is called. Care that a the overridden function may differ in number of parameters, regardless of their types.
Alse you can declare more than one overridden function if all of them are different in type or number of parameters.

2006-11-13 06:48:51 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers