Why to give the file name same as the public class name in
java?
Answer Posted / naresh kumar
If u dont keep public in front of class that is not
accessible by third party packages. But if u keep public
infront of class that is accessible by third party
packages.
Problem: class CheckServlet extends HttpServlet
{---- }
Now u want to executed this servlet class in server
(Tomcat,WebSphear,WebLogic) an error will come .Because the
above class is comes under default access modifier.
Ans: public class CheckServlet extends HttpServlet
{-------}
This class services will executed in any server(either
Tomcat,WebLogic etc.,). Because The class is visible in
third party class packages like container packages.
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
What do you understand by garbage collection in Java? Can it be forced to run?
How to compare two strings in java program?
What is blank final variable?
In a class implementing an interface, can we change the value of any variable defined in the interface?
What is difference between path and classpath in java?
Does the order of public and static declaration matter in main method?
What are the states of thread in java?
What do you mean by static variable?
Describe 2 different ways to concatenate two strings.
Why heap memory is called heap?
How do you classify Dialog Box?
What does a void function return?
How will you serialize a singleton class without violating singleton pattern?
What occurs when an object is constructed?
Which keyword specify that a variable is effectively final ?