Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Computer{
- public int brightness;
- public int volume;
- public void setBrightness(int inputBrightness){
- this.brightness = inputBrightness;
- }
- public void setVolume(int inputVolume){
- this.volume = inputVolume;
- }
- // 'This' method calls other methods from the class. Rather than create a new object, we use this as the object.
- // 'this' serves as a placeholder for whatever object was used to call the original method.
- public void resetSettings(){
- this.setBrightness(0);
- this.setVolume(0);
- }
- public static void main(String[] args){
- Computer myComputer = new Computer();
- myComputer.setBrightness(8);
- myComputer.setVolume(24);
- System.out.println(myComputer.brightness);
- System.out.println(myComputer.volume);
- myComputer.resetSettings(); //now both attributes will be reset to 0
- System.out.println(myComputer.brightness);
- System.out.println(myComputer.volume);
- }
- }
Add Comment
Please, Sign In to add comment