InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What will be the output in below code? |
|
Answer» PUBLIC class Demo{ public static void main(STRING[] arr){ System.out.println(“Main1”); } public static void main(String arr){ System.out.println(“Main2”); } } Output: Main1Reason: |
|
| 2. |
Predict the output? |
|
Answer» #include<iostream> using NAMESPACE std; class ClassA { public: ClassA(int ii = 0) : i(ii) {} void show() { cout << "i = " << i << ENDL;} private: int i; }; class ClassB { public: ClassB(int xx) : x(xx) {} operator ClassA() const { return ClassA(x); } private: int x; }; void g(ClassA a) { a.show(); } int main() { ClassB b(10); g(b); g(20); getchar(); return 0; } Output: i = 10i = 20Reason: |
|
| 3. |
What will be the output of the below code? |
|
Answer» class SCALER{ static INT i; static { System.out.println(“a”); i = 100; }}public class StaticBlock{ static { System.out.println(“b”); } public static void MAIN(String[] ARGS) { System.out.println(“c”); System.out.println(Scaler.i); }} Output: bca100Reason: |
|
| 4. |
What is the output of the below code? |
|
Answer» #include<iostream> using namespace std; class BaseClass1 { public: BaseClass1() { cout << " BaseClass1 constructor called" << endl; } }; class BaseClass2 { public: BaseClass2() { cout << "BaseClass2 constructor called" << endl; } }; class DERIVEDCLASS: public BaseClass1, public BaseClass2 { public: DerivedClass() { cout << "DerivedClass constructor called" << endl; } }; int main() { DerivedClass derived_class; return 0; } Output: BaseClass1 constructor calledBaseClass2 constructor calledDerivedClass constructor calledReason: |
|