0

JAVA CLASS, METHOD

How to declare a class and method in a programme

31st Dec 2023, 9:31 AM
CHANDAN MALLIK
CHANDAN MALLIK - avatar
2 Respostas
+ 6
31st Dec 2023, 10:31 AM
Ausgrindtube
Ausgrindtube - avatar
+ 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*/ }
1st Jan 2024, 3:28 PM
Maram