×
Log in
Twitter
Gmail
Facebook
.NET Fiddle
and
.NET Academy
shared account
Remember me
Log in
Sign up
or
Reset password
Search Tutorials
Log in
Sign up
About
Twitter
.NET Fiddle
Support
Contact Us
Visibility and Accessibility Modifiers
Exercise: Use the protected modifier
< Previous
Next >
Goal
Modify the example classes
Add a protected property to the class 'Student' named 'GraduationYear' of type int.
using System; public class Student { public Student(int graduationYear) { GraduationYear = graduationYear; } public int GetYearsSinceGraduation() { return DateTime.Now.Year - GraduationYear; } } public class Graduate : Student { public Graduate(int graduationYear) : base(graduationYear) { } public void GraduateToday() { GraduationYear = DateTime.Now.Year; } } public class Program { public static void Main() { var student = new Student(2006); Console.WriteLine("Years since gradation: {0}", student.GetYearsSinceGraduation()); } }
Reset
Verify
Page 7 of 18
< Previous
Next >
Loading packages and dependencies