In: Computer Science
C# programming
Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f.
Write your answer to all three questions below:
Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1?
variable d of class B and variable z have value 1 because this both are public variables so you can directly access it.
Create a method Foo in B and assign all fields accessible to the method with value of 2. Which fields will have a value of 2 now?
it will not give any compilation error but if you declare this variables then you will Hide Parent class's variable `x` by defining a variable in child class with same name.
If you have any query regarding the answer please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.
The following variables has value 2
d
e
f
y
z
x is the private variable of the class A so it can not be access in class B.