C# Class & Object Aptitude Questions and Answers | Set 3

C# Class & Object Aptitude Questions | Set 3: This section contains aptitude questions and answers on C# Class & Object.
Submitted by Nidhi, on April 12, 2020

1) What are the correct statements about given code snippets?
public class Example
{
    private int     X;
    public float    Y;

    private void method1()
    {
        Console.WriteLine("{0},{1}", X, Y);
 
    }

    public void method2()
    {
        Console.WriteLine("{0},{1}", X, Y);
    }

}
  1. No error
  2. Y cannot be declared as public
  3. Method1() should be static
  4. Method1() cannot access X

2) Can we create a static class in C#.NET?
  1. Yes
  2. No

3) What is the correct output of given code snippets?
using System;

public static class Example
{

    private void SayHi()
    {
        Console.WriteLine("Hiii");

    }

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
    }
}
  1. No error
  2. SayHi() must be static
  3. Cannot create static class
  4. SayHi() should be called in Main() method

4) What is the correct output of given code snippets?
using System;

public static class Example
{

    private int X;
    private int Y;

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
    }
}
  1. No error
  2. Compilation Error
  3. Cannot create a static class
  4. Runtime Exception

5) Can we create a virtual class in C#.NET?
  1. Yes
  2. No





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.