Public and Void | SoloLearn: Learn to code for FREE!

0

Public and Void

public means the visibility....visibility to whom?? Void says method dosent return a value..but without a method main..the program doesn't give output..why is that? and methods must be named..can we give any name instead of main method?? my doubts may be silly but please help me..I like programming

7/2/2016 4:43:17 PM

Srivatsa Balaji

7 Answers

New Answer

0

visibility to other classes. example if you make a class and make its fields (variables ) private you cannot access them directly from the main class for example. but if you make it public you can.

0

Yes you can name your method any name other than main

0

no that is something you cant do. it must be called , public static void main(String [] args ). those are just the rules.

0

but other methods that you make .you can name it what you want.

0

you need a good book. try head first Java or the complete Java reference.

0

visibility means scope of that class whether it can be accessed from other class or not. if you are a beginner then it will take some time to understand but don't worry you will get it.

0

coming to your second question void: execution always start from main method so main method is not going to return any value. let me show you an example. public void add() { a=1+2; System.out.print(a); } public int add1() { a=1+2; return(a); } in first case we are printing the value in same function but what if we need it in other method in second case we are returning the value you will have to store the value which is returned from the add1() function. so main method is not going to return any value to any function. Think yourself to whom main method should return