GeekInterview.com
Series: Subject: Topic:
Question: 260 of 338

What is function overriding?

Asked by: Interview Candidate | Asked on: Mar 24th, 2006
Showing Answers 1 - 24 of 24 Answers
navneet sahota

Answered On : Mar 26th, 2006

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

  
Login to rate this answer.
krishna pratap

Answered On : 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.

  
Login to rate this answer.
Manas

Answered On : 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)

Yes  1 User has rated as useful.
  
Login to rate this answer.
kamran

Answered On : Apr 2nd, 2006

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

Yes  4 Users have rated as useful.
  
Login to rate this answer.
sanneeta

Answered On : Apr 5th, 2006

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

  
Login to rate this answer.
minli

Answered On : Apr 9th, 2006

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

  
Login to rate this answer.
minli

Answered On : 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).

Yes  1 User has rated as useful.
  
Login to rate this answer.
Deebendu

Answered On : May 5th, 2006

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

Yes  1 User has rated as useful.
  
Login to rate this answer.
Mohan babu V B

Answered On : 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?

  
Login to rate this answer.
arunangshusaha

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
jalandhar

Answered On : 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;------------------------------------}};

Yes  1 User has rated as useful.
  
Login to rate this answer.
priti Kamath

Answered On : 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 ????

  
Login to rate this answer.
vishwa

Answered On : 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

  
Login to rate this answer.
Somesh Bhagat

Answered On : May 7th, 2007

  
Login to rate this answer.

Actually function overriding means the function signature have the same but differ in their body. but in case of overloading the functions have differ from their signature as well as function body only the name of the function is same,in case overloading.

  
Login to rate this answer.
chandu_salgar

Answered On : Apr 3rd, 2008

View all answers by chandu_salgar

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......... 

Yes  1 User has rated as useful.
  
Login to rate this answer.
SomGollakota

Answered On : May 25th, 2008

View all answers by SomGollakota

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;}

  
Login to rate this answer.
Archana

Answered On : Jul 13th, 2011

This def is of function overloading

  
Login to rate this answer.
Vignesh

Answered On : Jul 23rd, 2011

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

  
Login to rate this answer.

Function overriding means the functions have same name,parameters and typeof arguments but they differ mainly on their implementation.

  
Login to rate this answer.
Kannan

Answered On : 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..

  
Login to rate this answer.
chita ranjan patra

Answered On : 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. }

  
Login to rate this answer.
arpita

Answered On : 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.

  
Login to rate this answer.
Rudresh

Answered On : 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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.