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 happens to the Exception object after handling an exception?

1822


What is the purpose of the finally clause of a try-catch-finally statement in java programming?

521


What happens when you add a double value to a string?

561


Is ruby built on java?

541


What does a boolean method return?

646






Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.

1624


What is array pointers ?

613


What are the different access modifiers available in java?

571


Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?

627


What is outofmemoryerror in java?

577


Write a program to find maximum and minimum number in array?

563


Is there any difference between nested classes and inner classes?

554


Are private methods final?

495


How to make a write-only class in java?

585


Explain importance of inheritance in java?

615