Instance Method

1. Consider the following code, which is supposed to subtract a value passed to the method from an instance variable; however, there is a problem. Re-write this code, without renaming any variable names, to resolve the problem.

private int number = 542;

public void subtractNumbers (int number)

{

number = number – number;

System.out.println(“The local variable is: ” + number);

System.out.println(“The instance variable is: ” + number);

2. Consider the following segment of code.

SomeClass someObject1 = new SomeClass(23);

SomeClass someObject2 = new SomeClass(98.6);

SomeClass someObject3 = new SomeClass(23, 98.6);

3. Write a class method called subtractThese that will accept two integer values, and calculate and print their difference.

4. double rectangleArea = someObject.calcRectangleArea(1.5)

Write an instance method that calculates the area of a rectangle using a class constant of 14 feet for the base of the rectangle. The value passed to the method represents the height of the rectangle in feet.

Do you need help with this assignment or any other? We got you! Place your order and leave the rest to our experts.

Quality Guaranteed

Any Deadline

No Plagiarism