Tag: programming languages

Questions Related to programming languages

Destructors can be overloaded.

  1. True

  2. False


Correct Option: B

#include class NewInt { int num; public: NewInt(int n=0):num(n) {printf("cons\n");} int getInt() const {return num;} void setInt(int n){num =n;} ~NewInt(){printf("Dest\n");} }; int main() { NewInt a[5]; for(int i=0;i<=5;i++) a[i].setInt(i+10); for(int i=0;i<=5;i++) printf("%d\n",a[i].getInt()); return 0; } What does the above code snippet do?

  1. It creates an array of classes

  2. Gives compile time error

  3. It creates an array of objects

  4. It does nothing


Correct Option: C
  1. ?:(Ternary Operator)

  2. .(member access)

  3. () (Paranthesis)

  4. ::(scope resolution)


Correct Option: A,B,D
  1. private member

  2. Constructor

  3. Destructor

  4. Overloaded assignment operator


Correct Option: B,C,D
  1. The class compiles and runs, but does not print anything.

  2. The number 1 gets printed with AssertionError

  3. The number 2 gets printed with AssertionError

  4. The number 3 gets printed with AssertionError

  5. The program generates a compilation error.


Correct Option: B
  1. compiletime error at lines 1,2,3,4

  2. compiletime error at line 3

  3. compiletime error at line 1

  4. compiletime error at lines 3,4

  5. None of the above


Correct Option: D

class C1 { static interface I { static class C2 { } } public static void main(String a[]) { C1.I.C2 ob1=new C1.I.C2(); System.out.println("object created"); } } What is the result of attempting to compile and run the program?

  1. prints object created

  2. Compile time error

  3. Runtime Excepion

  4. None of the above


Correct Option: A