BreakInterview

1. Which of the following is true?

Static methods cannot be overloaded.
Non-static data members can be accessed by static methods.
Static data members can only be accessed by static methods.
Static methods can only access static members (data and methods)

2. Predict the output of the following code.
#include 
class Test
{
public:
    void breakInterview();
};
static void Test::breakInterview()   
{
    std::cout<<"breakInterview() is static\n";
}
int main()
{
    Test::breakInterview();   
    return 0;
}

breakInterview is static
Empty Screen
Compiler Error
Runtime Error

3. Assume that an integer takes 4 bytes and there is no alignment in following classes, predict the output.
#include
using namespace std;
 
class base {
    int arr[10];
};
 
class b1: public base { };
 
class b2: public base { };
 
class derived: public b1, public b2 {};
 
int main(void)
{
  cout << sizeof(derived);
  return 0;
}

40
80
4

4. Predict the output of the following code.
#include
using namespace std;
 
class Base {};
 
class Derived: public Base {};
 
int main()
{
    Base *bp = new Derived;
    Derived *dp = new Base;
}

No Compiler Error
Compiler Error in line “Base *bp = new Derived;”
Compiler Error in line ” Derived *dp = new Base;”
Runtime Error

5. Predict the output of the following code.
#include 
int main()
{
   const int x;
   x = 10;
   printf("%d", x);
   return 0;
}

10
Compiler Error
Runtime Error

6. Predict the output of the following code.
#include 
int const s=9;
int main()
{
    std::cout << s;
    return 0;
}

9
Compiler Error

7. What happens when delete is used for a NULL pointer?
int *ptr = NULL;
delete ptr;

Compiler Error
Run-time Crash
No Effect

8. Is it fine to call delete twice for a pointer?
#include
using namespace std;
 
int main()
{
    int *ptr = new int;
    delete ptr;
    delete ptr;
    return 0;
}

Yes
No

9. Can a constructor be virtual? Will the following program compile?
#include 
using namespace std;    
  
class Test
{
   public:
      virtual static void fun()  { }
};

Yes
No

10. Predict the output of the following code.
#include 
using namespace std;
 
template 
void fun()
{
   i = 20;
   cout << i;
}
 
int main()
{
   fun<10>();
   return 0;
}

10
20
Compiler Error