-
Notifications
You must be signed in to change notification settings - Fork 0
Java Modifiers
Ok, so if modelS has all the same properties, I should be able to access name or manufacturerName right?
System.out.println(modelS.name);Results in :
Main.java:13: error: name has private access in Car
System.out.println(modelS.name);
^
1 errorWhy? Notice we had mentioned private before the variable name in class Car. This marks the variable as private to the class which means that the variable cannot be modified or accessed from another class, even if an object of the class is instantiated. So, unless you provide a public setter method or any other public method to access the variable, there is no way it's visible to the outside world.
There are other kinds of access modifiers such as public, protected, default etc. Read more about them here.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links