PrepAway - Latest Free Exam Questions & Answers

Hot Area:

HOTSPOT
You have the following code:

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Hot Area:

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:
Note:
* CustomerID is declared private.
* CompanyName is declted protected.
* State is declared protected.
The protected keyword is a member access modifier. A protected member is accessible from within the class in
which it is declared, and from within any class derived from the class that declared this member.

8 Comments on “Hot Area:

  1. Hedz says:

    Shouldnt be No, No, No?

    MyCustomer Class have access to customer public and protected but creating a new class derived from MyCustomer dont have those properties eg:

    public class MyObject : MyCustomerClass
    {
    }
    class Q120
    {
    void Test() {

    MyObject obj = new MyObject();
    // no props
    obj.
    }
    }




    0



    9
    1. Denis says:

      public class MyDerivedClass : MyCustomerClass
      {
      public void Test()
      {
      this.CustomerId = 1;//error, can not access private property here
      this.CompanyName = “Name”;//ok
      this.State = “NY”;//ok
      }
      }




      9



      1
  2. Jah says:

    Correct: no, yes, yes
    CustomerId is private – answer no
    CompanyName is public – answer yes
    State is protected – means all objects derived from the class has acess – answer yes




    21



    1
    1. amgcgoncalves says:

      Before posting these replies, please open Visual Studio (Community edition is free, so there are no excuses) and test the code for yourself. Misleading answers harm those who are here to study and learn.

      The correct answer is, indeed: NO, YES, YES.




      12



      0
  3. z1ppz says:

    NO YES YES

    Code below shows whats available. CustomerId is not.

    public class Customer
    {
    private int CustomerId { get; set; }
    public string CompanyName { get; set; }
    protected string State { get; set; }
    public string City { get; set; }

    public Customer(int customerId, string companyName, string state, string city)
    {
    CustomerId = customerId;
    CompanyName = companyName;
    State = state;
    City = city;
    }
    public Customer() { }

    }

    public interface ICustomer
    {
    string GetCustomerById(int customerId);
    string GetCustomerByDate(DateTime dateFrom, DateTime dateTo);
    }

    public class MyCustomerClass : Customer, ICustomer
    {
    public string Zip { get; set; }
    public string Phone { get; set; }

    public string GetCustomerById(int customerId)
    {
    return null;
    }

    public string GetCustomerByDate(DateTime dateFrom, DateTime dateTo)
    {
    return null;
    }
    }

    public class DerivedTest : MyCustomerClass
    {
    public void TestMethod()
    {
    CompanyName = null;
    State = null;
    Zip = null;
    Phone = null;
    GetCustomerByDate(DateTime.MinValue, DateTime.Now);
    GetCustomerById(22);
    }
    }




    7



    0

Leave a Reply