My Report

C# Programming Practice Test 5


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which keyword is used to declare a base class method while performing overriding of base class methods?

2. What will be the output of the following C# code?

 
 class maths
 {
     public int length;
     public int breadth;
     public maths(int x, int y)
     {
         length = x;
         breadth = y;
         Console.WriteLine(x + y);
     }
     public maths(double x, int y)
     {
         length = (int)x;
         breadth = y;
         Console.WriteLine(x * y);
     }
 }
class Program
{
    static void Main(string[] args)
    {
        maths m = new maths(20, 40);
        maths k = new maths(12.0, 12);
        Console.ReadLine();
    }
}

3. To override a method in the subclass, the base class method should be defined as?

4. What will be the output of the following C# code?

 
 namespace ConsoleApplication4
 {
     abstract class A
     {
         public int i ;
         public int j ;
         public abstract void display();
     }    
     class B: A    
     {
         public int j = 5;
         public override void display() 
         {
             this.j = 3;
             Console.WriteLine(i + "  " + j);
         }
     }    
     class Program
     {
         static void Main(string[] args)
         {
             B obj = new B();
             obj.i = 1;
             obj.display();     
             Console.ReadLine();
         }
     }
 }

5. What is the process of defining a method in terms of itself, that is a method that calls itself?

6. Which statement correctly defines Interfaces in C#.NET?

7. Which of the following cannot be used to declare an interface correctly?

8. What will be the output of the following C# code?

 using System;
 public class BaseClass
 {
     public BaseClass()
     {
         Console.WriteLine("I am a base class");
     }
 }
 public class ChildClass : BaseClass
 {
     public ChildClass()
     {
         Console.WriteLine ("I am a child class");
     }
 static void Main()
 {
     ChildClass CC = new ChildClass();
 }
 }

9. What will be the output of the following C# code?

 
 class maths
 {
     public static void fun1()
     {
         Console.WriteLine("method 1 :");
     }
     public void fun2()
     {
         fun1();
         Console.WriteLine("method 2 :");
     }
     public void fun2(int k)
     {
         Console.WriteLine(k);
         fun2();
     }
 }    
 class Program
 {
     static void Main(string[] args)
     {
         maths obj = new maths();
         maths.fun1();
         obj.fun2(20);
         Console.ReadLine();
     }
 }

10. What will be the correct way to implement the interface in the following C# code?

  interface abc
   {
       string name
       {
           get;
           set;
       }
   }

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.