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:

HOTSPOT
You have the following code:

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

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.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Hedz

Hedz

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.
}
}

Denis

Denis

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
}
}

mig

mig

yeah the confusion was that he was creating a new instance of an object derived, not using directly an object derived

Jah

Jah

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

ab

ab

Correct one is no, yes, no
protected it is only accessed by immediate derived class.

z1ppz

z1ppz

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);
}
}

keyur

keyur

correct given ans