In java if we have a public class then what is the need to save the file with the same class name.
example...
Public class dog{
code here...
}
then we need to save the file as dog.java.
Why?
Stuart A. Burkett
Ranch Hand
Joined: May 30, 2012
Posts: 318
posted
0
This has been discussed many times here. Try searching. The best answer you will probably come up with is that that's what the designers of java decided to do. If you want to know the thinking behind that decision you will probably have to ask them.
class Test{} save file as Cool.java and try javac Cool.java ---> and what you find?
(and)
public class Test{} save file as Cool.java and try javac Cool.java ---> and what you find?
Seetharaman Venkatasamy wrote:first of all it is public , not Public and it is a convention to start class name with capital letter.
and now test below scenario.
class Test{} save file as Cool.java and try javac Cool.java ---> and what you find?
I think, it will compile, as there is no public class so any name can be used.
Seetharaman Venkatasamy wrote:
public class Test{} save file as Cool.java and try javac Cool.java ---> and what you find?
It'll not compile as there is a public class exists.
you are right. but Seetharaman intended that question for Aneek Bannerjee. You are now experienced Saloni , i think we should give chance to novice to answer the question.