97
Java class keyword
A Java class keyword is the most common keyword which is used to declare a new Java class. A class is a container that contains the block of code that includes field, method, constructor, etc.
A class is a template or blueprint from which objects are created. It is a logical entity. It can’t be physical.
Points to remember
- Every object is an instance of a class.
- A class can contain one or more classes. This concept can be called a nested class.
- We can assign only public, abstract, strictfp and final modifier to class. However, we can assign other modifiers like private, protected and static to the inner java class.
- A class name must be unique within a package.
- We can use a class keyword as Class.class to get a Class object without needing an instance of that class.
Example 1
Let’s see a simple example of a class keyword.
Output:
Hello World
Example 2
In this example, we declare two classes.
Output:
101 John William 25000
Example 3
Let’s see an example to declare the private class.
Output:
private class is invoked
Next TopicJava Keywords