What is function overriding?

Showing Answers 1 - 24 of 24 Answers

navneet sahota

  • Mar 26th, 2006
 

the ability to change the defiinition of an inherited method or attribute in a subclass.

  Was this answer useful?  Yes

krishna pratap

  • Mar 27th, 2006
 

the function overloading is the technique in which you can make the function with more than one name but only if you will change the paramaters or the number of the paramaters.

  Was this answer useful?  Yes

Manas

  • Mar 29th, 2006
 

If a base class is declared as virtual and derived class is declared as virtual.This redefinition of virtual in derived class is known as Function overriding(Parameters will b same)

kamran

  • Apr 2nd, 2006
 

Redefining a function in a derived class is called function overriding.

sanneeta

  • Apr 5th, 2006
 

The ability to change the definition of an inherited method or attribute in a subclass.

  Was this answer useful?  Yes

minli

  • Apr 9th, 2006
 

why one or more than? can you enlighten me? thanks!

  Was this answer useful?  Yes

minli

  • Apr 9th, 2006
 

A derived class can override a base-class member function by supplying a new version of that function with the same signature (if the signature were different, this would be function overloading rather than function overriding).

Deebendu

  • May 5th, 2006
 

overloading of a function with same declaration as defined into base class is called as function overriding.

Mohan babu V B

  • May 18th, 2006
 

Please tell me clearly about this function, am not aware of this.

This is not a GD to Discuss, so i want the perfect answer.

Am preparing for the honeywell interview.

Can u help me on this?

  Was this answer useful?  Yes

arunangshusaha

  • Jun 2nd, 2006
 

From derive class u can define a function with tha same singnature(name... ) as that form its base class.

-------- this tecnique is  called function overridding.

jalandhar

  • Jun 27th, 2006
 

Function Overloading means with in the class we can declare same function name, but arguments and return types are different.

Ex:

class Base {

public:

void fun(){ cout<<"base::Fun()"<<endl;

}

void fun(int a){ cout<< " base::Fun()"<<endl;

}

};

Overriding means base functionality can inherit the derived class, and implementaion will be different. Just like virtual functions.

Ex:

Class Base {

public:

virtual void fun(){

cout<<"base::fun()"<<endl;

}

};

class der: public Base

{

public:

void fun()

{

cout<< " der::fun()"<<endl;

--------------------

----------------

}

};

priti Kamath

  • Aug 17th, 2006
 

Function Overloading is a feature that happens within the same class and function overriding is a feature that happens within the inheritance chain by using the virtual keyword for that function in the base class. Overriding is evaluated during runtime and Overloading at compile time. Overriding means the function signature is same and Overloading needs  unique function signature.

Is this clear ????

  Was this answer useful?  Yes

vishwa

  • Sep 20th, 2006
 

lets try with an examplethere is a class A and having one public virtual member function test() which having the some parameters passing to it.class B is inherited from Class A then if we declare the test() function with the same parameters and defining with some defination then the function will be legal.this is called function overriding

  Was this answer useful?  Yes

Somesh Bhagat

  • May 7th, 2007
 

Overriding refers that to modifying the definition of base class method into the derived class with the same name and signature.

If we change the the definition of a method in a same class but with different  signature then it is known as Method Overloading/function overloading.

The signature OS a method/function  includes following
          * Number of parameters
          * Type of parameters
          * Sequence of parameters
 

  Was this answer useful?  Yes

function overriding........


class A {

     
public:
            virtual void compute() {

/*this may convert kgs to lbs */
              }
};

class B : public A {

public:
            void compute() {
/*this may convert cms to inches */
               }


};


a function defined in a base class and redefined in a derived class is known as  "function overriding" 
function must be declared as virtual in base class.........
functions prototype or signature must be same in both the classes.....
IT IS COMMON INTERFACE AND MULTIPLE IMPLEMENTATION......... 

Function Overriding: Redefining the behavior (function body) of a virtual function from a base class, in a child class. For example,

class MyBaseClass
{
    public:
        virtual int MyVirtualFunc(int x, char* y)
        {
              for(int i=0; i<x; i++) cout<<y;
              return x;
        }
};

class MyChildClass: public MyBaseClass
{
    public:
        int MyVirtualFunc(int x, char*y)
        { //I don't like what the base class version is doing. So, I will give my
           // version a new behaviour
           cout<< x;
           cout<< " -->";
           cout << y;
           return x;
        }
};

int main (int argv, char* argc)
{
     MyBaseClass mbc;
     MyChildClass mcc;

    mbc.MyVirtualFunc(2, "Hello");            // Output --> HelloHello
    mcc.MyVirtualFunc(2, "Hello");            // Output --> 2 --> Hello
    return 0;
}

  Was this answer useful?  Yes

Archana

  • Jul 13th, 2011
 

This def is of function overloading

  Was this answer useful?  Yes

Vignesh

  • Jul 23rd, 2011
 

Function overriding means the functions have the same name,type of arguments,parameters but they differ by their implementation only

  Was this answer useful?  Yes

Kannan

  • Jul 27th, 2011
 

Hi..
Over riding means we are getting through some functions...
Eg: In Java, assume..

Code
  1. Class A

  2. {

  3.   public void add()

  4.   {

  5.        System.out.println("This is from Class A");

  6.   }

  7. }

  8.  

  9. Class B extends A /*we are inheriting class A properties(methods and functions) to Class B*/

  10. {

  11.     public void add()

  12.     {

  13.         System.out.println("This is from Class B")

  14.     }

  15. }

  16.  

  17. Class MainFunction

  18. {

  19.   public static void main(String[] args)

  20.   {

  21.      B b=new b(); /* we are instantiating the class B  using the object name "b" */

  22.      b.add();        /* we are calling the add method by using the object b */

  23.   }

  24. }

  25.  

  26.  

The output for the above program is: This is from Class B
Here in Class A there is one function in the name of add().. In Class B also we are having the same method as add()
We are inheriting class A to B.. So if we create objects for B class we can access both Class A and Class B proporties because of inheritence..
In class B we call the add() method by using the object b as b.add()
at this point, the add() method in class B will execute... Because we are over-riding the base class method in sub class... So add() method in Class B will execute but not add() method in Class A.. We are forcing our object to over-ride add method in class B and so only we are getting our result as 'This is our class B"..
so we are forcing to over-ride the methods declared in the derived class.. This concept is called OVER RIDING..
In short and sweet, we can say over-riding occurs in same method name and same arguments... :)
If u want to print Class A methods means u can give like
A a=new A();
a.add();
at this point, u will get ur result as "This is from class A"...
So over-riding is possible only when it having the same method name and arguments in the derived class as like in base class.. Unless it wil treated as different and over riding will not possible..

  Was this answer useful?  Yes

chita ranjan patra

  • Jul 30th, 2011
 

Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.
The implementation in the subclass overrides (replaces) the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.
[1] The version of a method that is executed will be determined by the object that is used to invoke it. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, but if an object of the subclass is used to invoke the method, then the version in the child class will be executed.
[2] Some languages allow a programmer to prevent a method from being overridden.

Code
  1. public class Thought {

  2.     public void display message() {

  3.         System.out.println("I feel like I am diagonally parked in a parallel universe.");

  4.     }

  5. }

  6.  

  7. public class Advice extends Thought {

  8.     @Override  // @Override annotation in Java 5 is optional but helpful.

  9.     public void display message() {

  10.         System.out.println("Warning: Dates in calendar are closer than they appear.");

  11.     }

  12. }

  Was this answer useful?  Yes

arpita

  • Jan 15th, 2012
 

the name of function,return type,and no. of function are same in base class and derived class than it is known as function overriding.

  Was this answer useful?  Yes

Rudresh

  • Jan 18th, 2012
 

For a global objects and static class members, the initializer list doesnt invoke any code on run time. (Initialization data is stored directly in the binary).
If you are initializing a lot of objects, or if the constructor code is expensive / large, this can make a notable difference at load time.
As said, this is true only for plain old data, i.e. everything that can be initialized with an initializer list in

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions