Classes and Objects
notes
Classes and Objects
Access modifier: This specifies the level of access that other parts of your code have to the class. There are three main access modifiers in Java:
- Public: Can be accessed from anywhere.
- Protected: Can be accessed within the same package or by subclasses.
- Private: Can only be accessed within the same class.
- Accessor methods return a value they dont have a void
- mutator methods change the state of an
Static Methods
- ex: when calling : object.method(); ie: student.getName(); will reutrn the students name usings static methods
- math class provides static methods that we use through class.methdo();
- ie: (Math.abs(-45)); will print 45 using string class objects
Constructor: A special method that is used to create instances of the class. Constructors have the same name as the class and can take parameters to initialize the object's properties.
- have parameters
- ex: person teacher = new perseon("mr.s, 39, ohio");
Modifiers/setters: Allow you to modify the values of the class's properties. Modifiers aka "setters" because they set the value of a property to a new value. Usually named using the pattern set
.</p> </li> Getters: Allow you to get the values of the class's properties. Getters usually named using the pattern get
.</p> </li> </ul> </div> </div> </div> </div>