+ 8
Can i declare a function in this format
public int (int x)square{ return (x*x) }
4 Answers
+ 16
No. The parameters must be declared after method's name and you certainly want a return value:
public int square(int x) {
return x*x;
}
public: access modifier
int: type of return value
square: method's name
(int x): parameter list of your method
+ 15
@Very Hard
Yeah, thx!
Add static after access modifier if you want the method to be called without creating an object. Methods must also be static, if they are called from another static method, such as the main method.
+ 8
@Tashi N and don't forget "static"
0
no