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


Please Help Members By Posting Answers For Below Questions

What is the java project architecture?

1781


how to create multithreaded program? : Java thread

501


What is a stack class in java ?

605


What is treeset in java?

534


What happens when a thread cannot acquire a lock on an object in java programming?

540






How to check if linked list contains loop in java?

453


What are the 3 types of control structures?

522


What variables are stored in stack?

523


What is a jit compiler?

627


I don’t want my class to be inherited by any other class. What should I do?

571


What are features of java?

559


What is a line break example?

571


Break statement can be used as labels in java?

549


What is widening and narrowing in java? Discuss with an example.

554


Can we declare array without size in java?

545