Commit e0c89e13 authored by Martin Deinhofer's avatar Martin Deinhofer
Browse files

Fixed some errors related to access modifiers and member variables.

parent 1ab8340e
......@@ -16,8 +16,16 @@ public class TestUni {
//Register student Martin
uni.register(student);
uni.deregister(student);
//The member variables of Student are not directly accessible due to the private access modifier.
//Some member variables of class Student are not directly accessible due to the private access modifier.
//If you uncomment the following line you will get a compile error.
//student.name;
//the name variable is public and hence accessible.
System.out.println(student.name);
//The id variable is protected and hence accessible from subclasses or classes within the same package.
System.out.println(student.id);
//The grades variable is private and hence not directly accessible from anywhere outside.
//--> So the line below would not compile
//System.out.println(student.grades);
}
}
......@@ -11,7 +11,7 @@ public class TestUni {
//Student.name is public, hence accessible
System.out.println(stud.name);
//Student.id is protected, hence not accessible
//Student.id is protected, hence not accessible from another package if the class is not a subclass.
//System.out.println(stud.id);
//Student.grades is private, hence not accessible
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment