0
JAVA CLASS, METHOD
How to declare a class and method in a programme
2 Answers
+ 6
Have you started the Java course? You could also search the forum, code playground or elsewhere online. Check these out:
https://sololearn.com/compiler-playground/WZ8lkR6gTex6/?ref=app
https://sololearn.com/compiler-playground/W3uiji9X28C1/?ref=app
https://sololearn.com/compiler-playground/W0uW3Wks8UBk/?ref=app
+ 1
CHANDAN MALLIK Java
To declare class in your main file or file of another class
//Syntax
class class_name{
Class body=>methods and initialization of variables
}
To declare public class you should make it in a separate file
//Syntax
public class class_name{
/*To declare methods you should determine whether it's public or private and determine whether it'll return data and which data type it'll return or it won't return data then it's void and determine whether it'll have parameters or not*/
/*Example of public method that return integer value and take two parameters of type int and string*/
public int method_name(int i,String st){
Statements;
return Int_value;/*this statement required only when the method has a return data*/
}
/*Example of private method that don't have a return data and parameters*/
private void method_name(){
Statements;
}
/*If you want methods to call in the main method you should put "static" before the return type*/
}