Why to give the file name same as the public class name in
java?

Answers were Sorted based on User's Feedback



Why to give the file name same as the public class name in java?..

Answer / akanksha bansal

So that ,that class is accessible from some other class/file
as well

Is This Answer Correct ?    10 Yes 2 No

Why to give the file name same as the public class name in java?..

Answer / mahesh

First of all, it only has to be the same when the class is
public. And there is no explicit reason for that, it's just
a convention that came along with old versions of java and
people got used to it... They say it's because of the
limited capabilities of the compiler to compile
dependencies.

Is This Answer Correct ?    9 Yes 4 No

Why to give the file name same as the public class name in java?..

Answer / 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

More Core Java Interview Questions

when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service

4 Answers   Accenture,


What is the difference between a method and a procedure?

0 Answers  


Name the methods that used to get and set the text label displayed by a Buttonobject?

1 Answers  


what is use of session tracking ?with example?

1 Answers   Photon,


What is regex java?

0 Answers  






What is run-time class and system class? what is their purpose?

1 Answers  


What are predefined functions?

0 Answers  


What is passing parameters in java?

0 Answers  


1).what is the difference between below examples String s="vijay"; String s=new String("vijay");

12 Answers   Mascon, Satyam, TCS,


Differentiate between array list and vector in java.

0 Answers  


does java support pointers?

0 Answers  


What is difference between adapter class and listener?

0 Answers  


Categories