Home » Aptitude Questions and Answers » C# Aptitude Questions and Answers

C# Inheritance Aptitude Questions and Answers | Set 3

C# Inheritance Aptitude Questions | Set 3: This section contains aptitude questions and answers on C# Inheritance.
Submitted by Nidhi, on April 14, 2020

1) Which of the following, inheritance provides facilities?
  1. Inheritance is used to reuse existing facilities of the parent class.
  2. We can override the existing functionalities of the superclass.
  3. We can also implement new functionality in the child class.
  4. We can implement polymorphic behavior using inheritance.

Options:

  1. Only A
  2. Only B
  3. Only C
  4. A, B and C

2) We have two classes A and B then what is the correct way to implement inheritance between them?
  1. class A 
    { ... }
    class B : public A
    { ... }
    
  2. class A 
    { ... }  
    class B :  A
    { ... }
    
  3. class A 
    { ... }  
    class B : protected A
    { ... }
    
  4. class A
    {
    	...
    	class B
    	{ ... }
    }
    

Options:

  1. A
  2. B
  3. C
  4. D

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();
    }
}
  1. Name: Arvind, Address: New Delhi
    Id: 101, Salary: 60000
  2. Name: Arvind, Address: New Delhi
  3. Syntax Error
  4. Runtime Error

4) In C#.NET, which is not a type of inheritance?
  1. Single Inheritance
  2. Multiple Inheritance
  3. Top-level inheritance
  4. Hybrid inheritance

5) Can we implement "multiple inheritances" without using the interface?
  1. Yes
  2. No






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.