Which of the following are true about classes and struct?

Loading

Practice Inheritance –

Which of the following are true about classes and struct?

  1. A class is a reference type, whereas a struct is a value type.
  2. Objects are created using new, whereas structure variables can be created either using new or without using new.
  3. A structure variable will always be created slower than an object.
  4. A structure variable will die when it goes out of scope.
  5. An object will die when it goes out of scope.

Which of the following statements are correct about the structure d

Loading

Practice Inheritance –

Which of the following statements are correct about the structure declaration given below?

struct Book {
private String name;
protected int totalpages;
public Single price;
public void Showdata() {
Console.WriteLine(name + " " + totalpages + " " + price);
}
Book() {
name = " ";
totalpages = 0;
price = 0.0f;
}
}
Book b = new Book();
  1. We cannot declare the access modifier of totalpages as protected.
  2. We cannot declare the access modifier of name as private.
  3. We cannot define a zero-argument constructor inside a structure.
  4. We cannot declare the access modifier of price as public.
  5. We can define a Showdata() method inside a structure.

Predict the output of following program?


			  		

Loading

Practice Objects and Classes –

Predict the output of following program?

#include<iostream>
using namespace std;

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

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

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