Question: Create a class called Methods that has a single instance variable private int x , then write the following six methods in the class: A
Create a class called Methods that has a single instance variable private int x, then write the following six methods in the class:
A static method that takes no parameters, returns no value, and prints Hello, world!
An instance (non-static) method called print() that takes no parameters, returns no value, and prints the current value of the x instance variable like this: x is: x
A setter method for the x instance variable, whose parameter name is also x; remember the naming convention for setter methods and their return type!
The setter method must guarantee that x is never set to a value less than 0
If the setter argument is negative, it can either set x to 0 or leave x unchanged
A Methods constructor that takes one int parameter called x and calls the setter method to set the value of the x instance variable
A getter method for the x instance variable; remember the parameter and return types for getter methods!
A static void method called print(), whose single parameter is a Methods object, that prints the value of its parameters x instance variable this is method overloading
This method can use either the objects print() or its getter method to do this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
