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

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

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.