c++ ##_##_C#属性能力问题和解答 套装3

c++ ##_##

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

class Employee
{
    private int empid;

    public Employee()
    {
        empid = 101;
    }
    public int EmpId
    {
        get
        {
            return empid;
        }
    }
}

class program
{
    static void Main(string[] args)
    {
        Employee emp = new Employee();

        emp.EmpId = 102;
        Console.WriteLine(emp.EmpId);
    }
}

  1. 102

  2. 101

  3. Runtime exception

  4. Syntax error

Answer & Explanation

Correct answer: 4
Syntax error

The above code snippets will generate error, because it is read only property.

The output would be,

1)给定代码段的正确输出是什么?
 using System ;

class Employee
{
    private int empid ;

    public Employee ( )
    {
        empid = 101 ;
    }
    public int EmpId
    {
        get
        {
            return empid ;
        }
    }
}

class program
{
    static void Main ( string [ ] args )
    {
        Employee emp = new Employee ( ) ;

        emp . EmpId = 102 ;
        Console . WriteLine ( emp . EmpId ) ;
    }
}

  1. 102

  2. 101

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:4
语法错误

上面的代码段将产生错误,因为它是只读属性。

输出将是

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

class Employee
{
    private int empid;

    public int EmpId
    {
        get
        {
            return empid;
        }
    }
}

class program
{
    static void Main(string[] args)
    {
        Employee emp = new Employee();

        Console.WriteLine(emp.EmpId);
    }
}

  1. null

  2. 0

  3. Runtime exception

  4. Syntax error

Answer & Explanation

Correct answer: 2
0

The code snippet will print "0" on the console screen.

2)给定代码段的正确输出是什么?
  1. 空值

  2. 0

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:2
0

该代码段将在控制台屏幕上显示“ 0”

3) Which keyword is used in set accessor to set the value into data members?
  1. value

  2. val

  3. assign

  4. new

Answer & Explanation

Correct answer: 1
value

To set value in data members, we need to use value keyword in the set accessor.

3)在set访问器中使用哪个关键字将值设置为数据成员?
  1. 分配

答案与解释

正确答案:1

要在数据成员中设置值,我们需要在set访问器中使用value关键字。

4) Which keyword is used to get accessor to get value from data members?
  1. value

  2. val

  3. assign

  4. no need to use any keyword

Answer & Explanation

Correct answer: 4
no need to use any keyword

In get accessor, there is no need to use any keyword.

4)哪个关键字用于获取访问器以从数据成员获取价值?
  1. 分配

  2. 无需使用任何关键字

答案与解释

正确答案:4
无需使用任何关键字

在get访问器中,无需使用任何关键字。

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

class Employee
{
    private int empid;

    public Employee()
    {
        empid = 101;
    }
    private int EmpId
    {
        get
        {
            return empid;
        }
        set
        {
            empid = value;
        }
    }
}

class program
{
    static void Main(string[] args)
    {
        Employee emp = new Employee();

        emp.EmpId = 102;
        Console.WriteLine(emp.EmpId);
    }
}

Options:

  1. 102

  2. 101

  3. Runtime exception

  4. Syntax error

Answer & Explanation

Correct answer: 4
Syntax error

The above code snippets will generate error because we cannot access private property outside the class.

5)给定代码段的正确输出是什么?

选项:

  1. 102

  2. 101

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:4
语法错误

上面的代码段将产生错误,因为我们无法访问该类之外的私有属性。

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

c++ ##_##

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值