What will be the output of the program?


			  		

Loading

Practice Inheritance –

What will be the output of the program?

class A {     
final public int GetResult(int a, int b) {
return 0;
}
}
class B extends A {
public int GetResult(int a, int b) {
return 1;
}
}
public class Test {
public static void main(String args[]) {
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}

 

What is the output of the following code ?


			  		

Loading

Practice Inheritance –

What is the output of the following code ?

class A {
public int i;
protected int j;
}

class B extends A {
int j;
void display() {
super.j = 3;
System.out.println(i + " " + j);
}
}

class Output {
public static void main(String args[]) {
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
}
}

What is the output of the following program ?


			  		

Loading

Practice Inheritance –

What is the output of the following program ?


class A {
int i;
void display() {
System.out.println(i);
}
}
class B extends A {
int j;
void display() {
System.out.println(j);
}
}
class inheritance_demo {
public static void main(String args[]){
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}

What is the output of the following code ?


			  		

Loading

Practice Inheritance –

What is the output of the following code ?

class A {
public int i;
protected int j;
}

class B extends A {
int j;
void display() {
super.j = 3;
System.out.println(i + " " + j);
}
}

class Output {
public static void main(String args[]) {
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
}
}

What is the output of the following program ?


			  		

Loading

Practice Inheritance –

What is the output of the following program ?


class A {
int i;
void display() {
System.out.println(i);
}
}
class B extends A {
int j;
void display() {
System.out.println(j);
}
}
class inheritance_demo {
public static void main(String args[]){
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}

Predict the output of following program?


			  		

Loading

Practice Inheritance –

Predict the output of following program?

#include
using namespace std;

class Base {
private:
int i, j;
public:
Base(int _i = 0, int _j = 0): i(_i), j(_j) { }
};
class Derived: public Base {
public:
void show(){
cout<<" i = "< Categories C Programming, Inheritance Leave a comment

What will be the output of following program?


			  		

Loading

Practice Inheritance –

What will be the output of following program?

#include

using namespace std;
class P {
public:
void print() { cout <<" Inside P"; }
};

class Q : public P {
public:
void print() { cout <<" Inside Q"; }
};

class R: public Q { };

int main(void)
{
R r;
r.print();
return 0;
}

What will be the output of following program?


			  		

Loading

Practice Inheritance –

What will be the output of following program?

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

What is the output of following program.


			  		

Loading

Practice Inheritance –

What is the output of following program.

#include 
using namespace std;

class B;
class A {
int a;
public:
A():a(0) { }
void show(A& x, B& y);
};

class B {
private:
int b;
public:
B():b(0) { }
friend void A::show(A& x, B& y);
};

void A::show(A& x, B& y) {
x.a = 10;
cout << "A::a=" << x.a << " B::b=" << y.b;
}

int main() {
A a;
B b;
a.show(a,b);
return 0;
}

What is the output of following program?


			  		

Loading

Practice Inheritance –

What is the output of following program?

#include
using namespace std;

class Base
{
public:
void show()
{
cout<<" In Base ";
}
};

class Derived: public Base
{
public:
int x;
void show()
{
cout<<"In Derived ";
}
Derived()
{
x = 10;
}
};

int main(void)
{
Base *bp, b;
Derived d;
bp = &d;
bp->show();
cout << bp->x;
return 0;
}

What is the output of following program?


			  		

Loading

Practice Inheritance –

What is the output of following program?

#include
using namespace std;

class Base {};

class Derived: public Base {};

int main()
{
Base *bp = new Derived;
Derived *dp = new Base;
}

Which of the following statements is correct?

Loading

Practice Inheritance –

Which of the following statements is correct?

Which of the following statements are correct?

Loading

Practice Inheritance –

Which of the following statements are correct?

  1. A struct can contain properties.
  2. A struct can contain constructors.
  3. A struct can contain protected data members.
  4. A struct cannot contain methods.
  5. A struct cannot contain constants.