Public class in java

Q. Explain the concept of public classes in java. How they are useful? 

Ans. Public class methods and areas can be accessed from anywhere. But a file with java source code can only contain one public class whose name must also match, with the file name. If it presents, this public class corresponds to the application or the applet in which case the public keyword is essential to allow your web browser or applet viewer to demonstrate the applet.

Use of public classes:  If we want to offer access to these entities and if this access cannot do any harm public class is used.

Example:

Public class square

{    // public class

Public x, y, size;    // public instance variables

}

 

 

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.