×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

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

C# Class & Object Aptitude Questions | Set 4: 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?
using System;

public class Example
{
    virtual private int X;
    private int Y;

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
    }
}
  1. Hello World
  2. HelloWorld
  3. Syntax Error
  4. Runtime Exception

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

public class Example
{
    private int X;
    private int Y;

    Example()
    {
        this.X = 1;
        this.Y = 2;

    }
    static void Main(string[] args)
    {
        Example Ob = new Example();

        Console.WriteLine("{0}, {1}", Ob.X, Ob.Y);
    }
}
  1. 1, 2
  2. 12
  3. Syntax Error
  4. Runtime Exception

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

public class Example
{
    private int X;
    private int Y;

    public Example()
    {
        this.X = 1;
        this.Y = 2;

    }
    public static ShowData()
    {
        Console.WriteLine("{0}, {1}", this.X, this.Y);
    }
    static void Main(string[] args)
    {
        Example Ob = new Example();
        Ob.Show();
    }
}
  1. 1, 2
  2. 12
  3. Syntax Error
  4. Runtime Exception

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

public class Example
{
    public Example Method1()
    {
        Console.Write("####, ");
        return this;
    }
    public Example Method2()
    {
        Console.Write("@@@@, ");
        return this;
    }
    public Example Method3()
    {
        Console.Write("$$$$, ");
        return this;
    }
    static void Main(string[] args)
    {
        Example Ob = new Example();

        Ob.Method1().Method2().Method3();
    }
}
  1. ####, @@@@, $$$$,
  2. $$$$, @@@@, ####,
  3. Syntax Error
  4. Runtime Exception

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

public class Example
{
    public void SayHello()
    {
        Console.Write("Hello World");
    }
    
    static void Main(string[] args)
    {
        this.Method();
    }
}
  1. Hello World
  2. Hello world
  3. Syntax Error
  4. Runtime Exception



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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