Answers for "protected variable unity"

C#
1

protected variable unity

public class ClassA
 {
     private string text1;
     protected string text2;
     public ClassA()
     {
         text1 = "aaa"; // ok
         text2 = "bbb"; // ok
     }
 }
 public class ClassB : ClassA
 {
     public ClassB()
     {
         text1 = "aaa"; // compile error - you can't access text1, because it is visible only in scope of ClassA
         text2 = "bbb"; // ok - text2 is declared as protected in ClassA, so it is accessible in ClassA and all the classes derived from ClassA
     }
 }
Posted by: Guest on March-13-2021

C# Answers by Framework

Browse Popular Code Answers by Language