Advertisement
danzylrabago

protected

Mar 31st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. // This code will give error as
  2. //protected members of the class Dog cannot be accessed outside of the class
  3. using System;
  4.  
  5. public class Dog
  6. {
  7. int Age=5;
  8. protected string gender="female";
  9. protected void getAge()
  10. {
  11. Console.WriteLine("Doggo's age is: {0}", Age);
  12. }
  13. }
  14.  
  15. class ProtectedExample
  16. {
  17. static void Main()
  18. {
  19. Dog dogobj = new Dog();
  20. dogobj.getAge();
  21. Console.WriteLine(dogobj.gender);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement