In putty and intelliJ need to change addition and subtraction to static methods
ID: 3882750 • Letter: I
Question
In putty and intelliJ need to change addition and subtraction to static methods
This is supposed to be my output for putty
PreviousNext
This has to be my results for intelli J
THANKS
AriaThurin@o2-ist-linux-fa17-242: GNU nano 2.7.4 File: Calculate.java blic class Calculate { public static int addition (int valuel, int value2) valuel + value2: public static int subtraction (int valuel, int value2) valuel - value2: public static int multiply (int valuel, int value2) valuel value2: public static int division (int valuel, int value2) return valuel / value2: Read Get Help Exit Write Out Read File Where Is Replace Cut Text Uncut Text Justif To Spell Cur Pos Prev Page Next Page Fir t Line La t Line Where! Nex Mark Text T Bracket Copy Text 11:25 PM 09/10/20177 Type here to searchExplanation / Answer
This is little tricky for you to understand. Though it's an implicit issue, they cannot fix this due to compatibility reasons. All the code is already out there. See, Java allows you to make a Method Static. This removes the dependency on creating an object and then accessing the method but it doesn't imply that you cannot call a method the traditional way, ObjectName.MethodName()
For example:
Class Square{
public static int area(int side){
return side*side;
}
}
Public Class Figure{
public static void main(String[] args){
int side= Integer.parseint(args[0]);
Square Obj = new Square();
System.out.print("Area:" + Square.area(side));
System.out.print("Area( Method called on object):" + Obj.area(side));
}
}
These two methods yield the same result because JAVA doesn't differentiate between these calls, even if the object is defined as NULL, it would still call the static function.
In intelliJ, giving values x=5, y=10 would yield the result expected.
Hope it's clear.