Question
I have a question on setters and getters and the 'this' keyword. So if I have a public void named public void setTime(int time), then
I have a question on setters and getters and the 'this' keyword. So if I have a public void named public void setTime(int time), then can I have anything in the method I want like the calculations for the accleration of the object in reference to time or the height of an object at a certain time or even the user input for the int time like time = scanner.nextDouble; ? and can the getters (which I believe are called accessor methods) can anything besides a return statement in it? And I have three more questions on the keyword 'this'. I know the keyword 'this' can be used like this.time = time; which sets the instance var to the parameter, but does the parameter need to be int time? And finally, does the this.time be used in calculation like this.time + 2 = z and is there a difference in if I put this.time = time at the beginning of the method or at the end of the method after all calculations equations are added?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Lets break down your questions In the setTime method you can perform any operations you need such as ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started