Does It must have the state private or public?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does It must have the state private or public??

When you declare a method first visibility, second type of return value and then the Name and the args

7th Sep 2019, 12:18 PM
andres
3 Answers
+ 4
Pls clarify what u want to know dude.
7th Sep 2019, 12:21 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 2
U have to calrify it according to ur use,suppose if u want a method to be access from outside a class u have to make it public , if u didn't clarify than it is private by default. Void means the method is not returning any value u have to write this whenever u create a method if it returning anything or if it is not. Byt incase of constructor u are free ,u don't need to use void because a constructor has no return type. I hope u get what i want to say.
7th Sep 2019, 12:38 PM
Piyush Srivastava
Piyush Srivastava - avatar
0
in a method When you write it Do you have to specify the visibility Example: public int max() also? -> void hello()
7th Sep 2019, 12:30 PM
andres