Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
embedded_systems_public
Java-Exercises-2-OOP1
Commits
e0c89e13
Commit
e0c89e13
authored
Nov 16, 2017
by
Martin Deinhofer
Browse files
Fixed some errors related to access modifiers and member variables.
parent
1ab8340e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/java_exercises2_1_1/TestUni.java
View file @
e0c89e13
...
...
@@ -16,8 +16,16 @@ public class TestUni {
//Register student Martin
uni
.
register
(
student
);
uni
.
deregister
(
student
);
//
Th
e member variables of Student are not directly accessible due to the private access modifier.
//
Som
e 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);
}
}
src/java_exercises2_1_1/other/TestUni.java
View file @
e0c89e13
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment