1) Which of the following, inheritance provides facilities?
- Inheritance is used to reuse existing facilities of the parent class.
- We can override the existing functionalities of the superclass.
- We can also implement new functionality in the child class.
- We can implement polymorphic behavior using inheritance.
Options:
- Only A
- Only B
- Only C
- A, B and C
Correct answer: 4
A, B and C
The statements A, B and C are correct; these facilities are provided by inheritance.
2) We have two classes A and B then what is the correct way to implement inheritance between them?
-
class A
{ ... }
class B : public A
{ ... }
-
class A
{ ... }
class B : A
{ ... }
-
class A
{ ... }
class B : protected A
{ ... }
-
class A
{
...
class B
{ ... }
}
Options:
- A
- B
- C
- D
Correct answer: 2
B
The 2nd option is correct way to implement inheritance between class A and B.
3) What is the correct output of given code snippets in C#.NET?
using System;
class Person
{
private string name;
private string address;
public void setPerson(string n, string add)
{
name = n ;
address = add ;
}
public void printPersonDetail()
{
Console.WriteLine("Name: {0}, Address: {1}", name, address);
}
}
class Employee : Person
{
private int id ;
private int salary ;
public void setEmployee(int ID, int sal)
{
id = ID ;
salary = sal ;
}
public void printEmployeeDetail()
{
Console.WriteLine("Id: {0}, Salary: {1}", id, salary);
}
}
class program
{
static void Main(string[] args)
{
Employee E = new Employee();
E.setPerson("Arvind", "New Delhi");
E.setEmployee(101, 60000);
E.printPersonDetail();
E.printEmployeeDetail();
}
}
- Name: Arvind, Address: New Delhi
Id: 101, Salary: 60000
- Name: Arvind, Address: New Delhi
- Syntax Error
- Runtime Error
Correct answer: 1
Name: Arvind, Address: New Delhi
Id: 101, Salary: 60000
The first option is the correct output of the above code.
4) In C#.NET, which is not a type of inheritance?
- Single Inheritance
- Multiple Inheritance
- Top-level inheritance
- Hybrid inheritance
Correct answer: 3
Top-level inheritance
In C#.NET, there is no inheritance named "Top-level" inheritance.
5) Can we implement "multiple inheritances" without using the interface?
- Yes
- No
Correct answer: 2
No
No, we cannot implement "multiple inheritances" without using an interface.