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
Differentiate between postfix and prefix operators in java.
Explain an algorithm to find depth of a binary tree.
Why is the singleton pattern considered to be an anti pattern?
How do you reverse a string in java without using string buffer?
What is the difference between an interface and an abstract class?
What is the difference between final, finally and finalize()?
Can we execute a program without main() method?
Is it possible to compare various strings with the help of == operator? What are the risks involved?
What is the purpose of default constructor?
Can a constructor have different name than a class name in java?
how its run?
Can array grow dynamically in java?
What’s the difference between applets and standalone program?
What do you mean by order of precedence and associativity?
Do I need java on my pc?