c# 构造函数 析构函数_C#构造函数和析构函数的能力问题和解答

c# 构造函数 析构函数

1) There are following statements are given below, which of them are correct about constructors in C#.NET?
  1. Constructors are not required in a class.

  2. Constructors are used to initializing data members of the class.

  3. The constructor name and class name must be the same.

  4. Contractors are old technique, now a day they are deprecated.

Options:

  1. Only A

  2. Only D

  3. B and C

  4. A and D

Answer & Explanation

Correct answer: 3
B and C

B and C are correct statements about constructors in C#.NET.

1)下面给出了以下语句,其中哪些对于C#.NET中的构造函数是正确的?
  1. 在类中不需要构造函数。

  2. 构造函数用于初始化类的数据成员。

  3. 构造函数名称和类名称必须相同。

  4. 承包商是一种古老的技术,如今已经过时了。

选项:

  1. 只有一个

  2. 只有D

  3. B和C

  4. A和D

答案与解释

正确答案:3
B和C

B和C是有关C#.NET中构造函数的正确声明。

2) There are following statements are given below, which of them are NOT correct about constructors in C#.NET?
  1. A constructor does not have any return type.

  2. Constructors can be overloaded.

  3. Constructors cannot be overloaded.

  4. A constructor is called when an object of the class gets created.

Options:

  1. Only A

  2. Only B

  3. Only C

  4. Only D

Answer & Explanation

Correct answer: 3
Only C

Only C statement is not correct about construct in C#.NET.

2)下面给出了以下语句,其中哪些与C#.NET中的构造函数不正确?
  1. 构造函数没有任何返回类型。

  2. 构造函数可以重载。

  3. 构造函数不能重载。

  4. 创建类的对象时,将调用构造函数。

选项:

  1. 只有一个

  2. 只有B

  3. 只有C

  4. 只有D

答案与解释

正确答案:3
只有C

关于C#.NET中的构造,仅C语句是不正确的。

3) In C#.NET, constructor is a?
  1. Method

  2. Class

  3. Variable

  4. Keyword

Answer & Explanation

Correct answer: 1
Method

In C#.NET, a constructor is a special type of method, which is used to initialize data members of a class.

3)在C#.NET中,构造函数是?
  1. 方法

  2. 变量

  3. 关键词

答案与解释

正确答案:1
方法

在C#.NET中,构造函数是一种特殊的方法,用于初始化类的数据成员。

4) If we do not create a constructor in a class, then compiler inserts a default constructor automatically?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes it is true.

4)如果我们不在类中创建构造函数,那么编译器会自动插入默认构造函数吗?
  1. 没有

答案与解释

正确答案:1

是的,它是真的。

5) Can we create a constructor with an empty body in C#.NET?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes it is true.

5)我们可以在C#.NET中创建带有空主体的构造函数吗?
  1. 没有

答案与解释

正确答案:1

是的,它是真的。

6) In C#.NET, how many times we can call a constructor during the lifetime of the object?
  1. It depends upon the setting in Visual studio.

  2. Any number of times it can be called by the programmer explicitly.

  3. Only One time.

  4. 2 times only.

Answer & Explanation

Correct answer: 3
Only One time.

A constructor is called only one time when an object gets created.

6)在C#.NET中,在对象的生存期内我们可以调用构造函数多少次?
  1. 这取决于Visual Studio中的设置。

  2. 程序员可以显式调用任意多次。

  3. 只有一次。

  4. 仅2次。

答案与解释

正确答案:3
只有一次。

创建对象时,只会一次调用构造函数。

7) We can use default arguments in constructors also?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes it is true.

7)我们也可以在构造函数中使用默认参数吗?
  1. 没有

答案与解释

正确答案:1

是的,它是真的。

8) There are the following options are given below, which is not the type of constructor in C#.NET?
  1. Default Constructor

  2. Copy Constructor

  3. Parameterized constructor

  4. Body Constructor

Answer & Explanation

Correct answer: 4
Body Constructor

In C#.NET, Body constructor is not a type of constructor.

8)下面给出了以下选项,这不是C#.NET中的构造函数类型吗?
  1. 默认构造函数

  2. 复制构造函数

  3. 参数化构造函数

  4. 身体构造器

答案与解释

正确答案:4
身体构造器

在C#.NET中,主体构造函数不是构造函数的一种。

9) There are following statements are given below, which of them are correct in C#.NET?
  1. A constructor is used to write code in a simple manner.

  2. A class can contain multiple destructors.

  3. A constructor is basically used to set default values in data members associated with an object.

  4. A copy constructor is used in C#.NET

Opyions:

  1. Only A

  2. C and D

  3. Only C

  4. Only D

Answer & Explanation

Correct answer: 2
C and D

In the above statements, only C and D statements are correct.

9)下面给出了以下语句,其中哪些在C#.NET中正确?
  1. 构造函数用于以简单的方式编写代码。

  2. 一个类可以包含多个析构函数。

  3. 构造函数基本上用于在与对象关联的数据成员中设置默认值。

  4. 在C#.NET中使用复制构造函数

py

  1. 只有一个

  2. C和D

  3. 只有C

  4. 只有D

答案与解释

正确答案:2
C和D

在以上语句中,只有C和D语句正确。

10) Can we pass a parameter to the destructor in C#.NET?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 2
No

No, we cannot pass any parameter to the destructor.

10)我们可以在C#.NET中将参数传递给析构函数吗?
  1. 没有

答案与解释

正确答案:2
没有

,我们不能将任何参数传递给析构函数。

11) There are the following options are given below, in which option we need to use a tilde (~) operator?
  1. Default constructor

  2. Copy constructor

  3. Destructor

  4. Super constructor

Answer & Explanation

Correct answer: 3
Destructor

In C#.NET, the tilde (~) operator is used with a destructor.

11)下面给出了以下选项,我们需要在其中使用波浪号(〜)运算符?
  1. 默认构造函数

  2. 复制构造函数

  3. 析构函数

  4. 超级构造函数

答案与解释

正确答案:3
析构函数

在C#.NET中,波浪号(〜)运算符与析构函数一起使用。

12) There are following statements are given below, which of them are correct about destructors in C#?
  1. A destructor is a special type of method, it automatically invokes when an object of the class gets destroyed.

  2. We need to use a tilde (~) operator to define a destructor.

  3. A destructor is used to reload the data member's value.

  4. We can create multiple destructors in a class.

Options:

  1. Only A

  2. A and B

  3. Only C

  4. C and D

Answer & Explanation

Correct answer: 2
A and B

12)下面给出了以下语句,其中哪些对于C#中的析构函数是正确的?
  1. 析构函数是一种特殊的方法,当销毁该类的对象时,它将自动调用。

  2. 我们需要使用波浪号(〜)运算符来定义析构函数。

  3. 析构函数用于重新加载数据成员的值。

  4. 我们可以在一个类中创建多个析构函数。

选项:

  1. 只有一个

  2. A和B

  3. 只有C

  4. C和D

答案与解释

正确答案:2
A和B

13) A destructor has the same name as class name in C#.NET?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes it is true.

13)析构函数的名称与C#.NET中的类名称相同吗?
  1. 没有

答案与解释

正确答案:1

是的,它是真的。

14) What is the return type of a destructor?
  1. Void

  2. Integer

  3. It does not have any return type

  4. It returns an object of the structure

Answer & Explanation

Correct answer: 3
It does not have any return type

A destructor does not have any return type.

14)析构函数的返回类型是什么?
  1. 空洞

  2. 整数

  3. 没有任何返回类型

  4. 它返回结构的对象

答案与解释

正确答案:3
没有任何返回类型

析构函数没有任何返回类型。

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

public class Example
{

    int X;
    int Y;

    public static Example()
    {
        X = 10;
        Y = 10;
    }

    public void show()
    {
        Console.WriteLine(X + " " + Y);
    }
    
    static void Main(string[] args)
    {
        Example Ob = new Example();
        Ob.show();
    }
}

  1. 10 10

  2. 1o 1o

  3. Runtime Exception

  4. Syntax Error

Answer & Explanation

Correct answer: 4
Syntax Error

We cannot use "static" keyword constructor.

15)给定代码段的正确输出是什么?
  1. 10 10

  2. 1o 1o

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:4
语法错误

我们不能使用“静态”关键字构造函数。

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

public class Example
{
    int X;
    int Y;

    public example()
    {
        X = 10;
        Y = 10;
    }

    public void show()
    {
        Console.WriteLine(X + " " + Y);
    }
    
    static void Main(string[] args)
    {
        Example Ob = new Example();
        Ob.show();
    }
}

  1. 10 10

  2. 1o 1o

  3. Runtime Exception

  4. Syntax Error

Answer & Explanation

Correct answer: 4
Syntax Error

C# is a case sensitive language, in the above program constructor name is different from the class name.

16)给定代码段的正确输出是什么?
  1. 10 10

  2. 1o 1o

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:4
语法错误

C#是区分大小写的语言,在上面的程序中构造函数名称与类名称不同。

17) What is the correct way to create an object of a given class?
public class Example
{
    int X;
    int Y;

    public Example(int x, int y)
    {
        X = x;
        Y = y;
    }
}

  1. Example E = new Example();

  2. Example E = Example(10,20);

  3. Example E = new Example(10,20);

  4. Example E(10,20);

Answer & Explanation

Correct answer: 3
Example E = new Example(10,20);

3rd option is the correct way to create an object of a given class.

17)创建给定类的对象的正确方法是什么?
  1. 例E = new Example();

  2. 例E =例(10,20);

  3. 例E =新例(10,20);

  4. 例E(10,20);

答案与解释

正确答案:3
例E =新例(10,20);

第三个选项是创建给定类的对象的正确方法。

18) What are the correct ways to define constructors of given code snippets?
Employee E1 = new Employee ("Shaurya");
Employee E2 = new Employee ("Shaurya", 5);

Code 1:

Code 2:

public Employee(int a)
{
	name = "shaurya";
	age = a;
}
public Employee(string n, int a)
{
	name = n;
	age = a;
}

Code 3:

Code 4:

public Employee(int a)
{
	name = "shaurya";
	age = a;
}
public Employee(int n, sting a)
{
	name = n;
	age = a;
}

  1. Code 1

  2. Code 2

  3. Code 3

  4. Code 4

Answer & Explanation

Correct answer: 1
Code 1

The Code 1 is the correct way to define constructors.

18)定义给定代码段的构造函数的正确方法是什么?

代码1:

 public Employee ( string n )
{
	name = n ;
	age = 5 ;
}
public Employee ( string n , int a )
{
	name = n ;
	age = a ;
}

代码2:

代码3:

 public Employee ( )
{
	name = " shaurya " ;
	age = 5 ;
}
public Employee ( string n , int a )
{
	name = n ;
	age = a ;
}

代码4:

  1. 代码1

  2. 代码2

  3. 代码3

  4. 代码4

答案与解释

正确答案:1
代码1

代码1是定义构造函数的正确方法。

19) Can we create a private constructor in a class?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes it is true.

19)我们可以在类中创建私有构造函数吗?
  1. 没有

答案与解释

正确答案:1

是的,它是真的。

20) Can we use the private keyword to define destructor in class?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 2
No

We cannot use the private keyword to define a destructor of the class.

20)我们可以使用private关键字在类中定义析构函数吗?
  1. 没有

答案与解释

正确答案:2
没有

我们不能使用private关键字定义该类的析构函数。

21) Can we use the public keyword to define destructor in class?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 2
No

We cannot use the public keyword to define a destructor of the class.

21)我们可以使用public关键字在类中定义析构函数吗?
  1. 没有

答案与解释

正确答案:2
没有

我们不能使用public关键字定义该类的析构函数。

22) There are following statements are given below, which of them are correct about copy constructor in C#?
  1. A copy constructor is an old technique, it is deprecated nowadays.

  2. A copy constructor is not supported in C#.NET.

  3. A copy constructor is used to initialize an object from an existing object.

  4. A copy constructor is also known as a no-argument constructor.

Options:

  1. Only A

  2. Only B

  3. C and D

  4. Only C

Answer & Explanation

Correct answer: 4
Only C

Only C statement is correct about copy constructor.

22)下面给出了以下语句,其中哪些对于C#中的复制构造函数是正确的?
  1. 复制构造函数是一种古老的技术,如今已不推荐使用。

  2. C#.NET不支持复制构造函数。

  3. 复制构造函数用于从现有对象初始化对象。

  4. 复制构造函数也称为无参数构造函数。

选项:

  1. 只有一个

  2. 只有B

  3. C和D

  4. 只有C

答案与解释

正确答案:4
只有C

关于复制构造函数,只有C语句正确。

23) There are following constructors are given below, which is also known as no argument constructor?
  1. Default constructor

  2. Parameterized constructor

  3. Copy constructor

  4. Body constructor

Answer & Explanation

Correct answer: 1
Default constructor

A default constructor is also known as a no-argument constructor.

23)下面给出了以下构造函数,也称为无参数构造函数?
  1. 默认构造函数

  2. 参数化构造函数

  3. 复制构造函数

  4. 身体构造器

答案与解释

正确答案:1
默认构造函数

默认构造函数也称为无参数构造函数。

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

class Employee
{
    string name;
    int age;

    public Employee()
    {
        name = "shaurya";
        age = 5;
    }

    public Employee(Employee E)
    {
        name = E.name;
        age =  E.age;
    }

    public void show()
    {
        Console.WriteLine(name + " " + age);
    }

    static void Main(string[] args)
    {
        Employee e1 = new Employee();
        Employee e2 = new Employee(e1);

        e1.show();
        e2.show();
    }
}

  1. shaurya 5
    shaurya 5

  2. shaurya
    shaurya

  3. Runtime Exception

  4. Syntax Error

Answer & Explanation

Correct answer: 1
shaurya 5
shaurya 5

1st option is the correct answer for the code snippets.

24)给定代码段的正确输出是什么?
  1. 绍里亚5
    绍里亚5

  2. 绍里亚
    绍里亚

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:1
绍里亚5
绍里亚5

第一个选项是代码段的正确答案。

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

class Employee
{
    string name;
    int age;

    public Employee()
    {
        this.name = "shaurya";
        age = 5;
    }

    public Employee(Employee E)
    {
        name = E.name;
        this.age =  E.age;
    }

    public void show()
    {
        Console.WriteLine(name + " " + age);
    }

    static void Main(string[] args)
    {
        Employee e1 = new Employee();
        Employee e2 = new Employee(e1);

        e1.show();
        e2.show();
    }
}

  1. shaurya 5
    shaurya 5

  2. shaurya
    shaurya

  3. Runtime Exception

  4. Syntax Error

Answer & Explanation

Correct answer: 1
shaurya 5
shaurya 5

1st option is the correct answer for the code snippets.

25)给定代码段的正确输出是什么?
  1. 绍里亚5
    绍里亚5

  2. 绍里亚
    绍里亚

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:1
绍里亚5
绍里亚5

第一个选项是代码段的正确答案。

翻译自: https://www.includehelp.com/dot-net/csharp-constructors-and-destructors-aptitude-questions-and-answers.aspx

c# 构造函数 析构函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值