Home >Java >javaTutorial >What does public class mean in java
The meaning of public class in Java: Define a new class, with the first letter of the class name capitalized. Classes can be accessed by classes in the same package or from other packages. Classes consist of data members (fields) and methods.
The meaning of public class in Java
In Java, public class
is Keywords that declare a new class. It has the following meaning:
1. Access permission
public
indicates that the class can be accessed by other classes in the same package as well as other packages class access. 2. Class definition
class
means defining a new class. 3. Class structure
Example:
<code class="java">public class MyClass { // 数据成员 private String name; // 方法 public void sayHello() { System.out.println("Hello from " + name); } }</code>
In this example:
public class MyClass
declares a A new class named MyClass
, which can be accessed by other classes. private String name;
declares a private data member named name
. public void sayHello()
declares a public method named sayHello
, which outputs a message. Note:
public class
The keyword must be the first line of the class declaration. MyClass
and myclass
are different classes. The above is the detailed content of What does public class mean in java. For more information, please follow other related articles on the PHP Chinese website!