C++ interview questions, some Java

  1. In C++, what is the difference between method overloading and method overriding?Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.
  2. What methods can be overridden in Java? In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.
  3. In C, what is the difference between a static variable and global variable? A static variable declared outside of any function is accessible only to all the functions defined in the same file (as the static variable). However, a global variable can be accessed by any function (including the ones from different files).
  4. In C, why is the void pointer useful? When would you use it? The void pointer is useful becuase it is a generic pointer that any pointer can be cast into and back again without loss of information.
  5. What are the defining traits of an object-oriented language? The defining traits of an object-oriented langauge are:
    • encapsulation
    • inheritance
    • polymorphism
This entry was posted in C++. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

8 Comments on C++ interview questions, some Java

  1. Ashish Ujwal
    Posted 12/25/2003 at 5:00 am | Permalink

    Please note that in case the base class has a non virtual function and derived class implements a function with the same prototype, the compiler would signal an error(derived class function hiding the base class implementation)

  2. Himanshu Chaturvedi
    Posted 1/28/2004 at 12:21 am | Permalink

    Question’s are good but add something related to OOPS and Macro’s

  3. Anonymous
    Posted 12/1/2004 at 10:04 am | Permalink

    I just want you to know that I think you did a terrific job on this websight.

  4. bear
    Posted 3/19/2006 at 9:03 pm | Permalink

    I am very confused, when the answer mentioned override must be virtual function. Ashish Ujwal’s comment even more confused me. I just tried VC++, I did not get any compiling error.

  5. Rakesh N.E
    Posted 7/29/2006 at 6:27 am | Permalink

    Thanks you for your grat service.. Please try to include more questions and answers from MFC.

    Thanks & Regards
    Rakesh Nhalil Edavalath

  6. vijay
    Posted 11/5/2006 at 6:57 am | Permalink

    Hai friends,

    I want to execute the PL/SQL program to findout the maximum of given 10 numbers.

    i.e.,
    Declare
    n number(5):=&n;
    big number(5);
    i number(2):=1;
    Begin
    big:=n;
    for i in 2..10
    loop
    n:=&n;
    if big

  7. banu
    Posted 8/3/2007 at 11:26 am | Permalink

    I need code for reverse of a string without using string functions in C++

  8. Nayna
    Posted 2/24/2008 at 11:13 pm | Permalink

    As Ashish Ujwal told “#

    Please note that in case the base class has a non virtual function and derived class implements a function with the same prototype, the compiler would signal an error(derived class function hiding the base class implementation) ”

    I tried exactly the similar functionality defining void print() function in both base and derived class. It compiles and runs perfectly fine without any errors in g++. So, in what case does the error you have described has occurred.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*