Using a predefined class name as a class name
Let us see an example −
Example
public class Number{ public static void main (String[] args){ System.out.println("Pre-defined class name can be used as a class name"); } }
Output
Pre-defined class name can be used as a class name
The class Number has a main function that displays a message when it is executed. The main function takes string values as arguments.
Using a predefined class name as a variable name
Let us see an example −
Example
public class String{ public static void main (java.lang.String[] args){ System.out.println("Pre-defined class name can be used as a variable"); } }
Output
Pre-defined class name can be used as a variable
The String class has the main function that displays a relevant message on the console. Here, the only difference is that the main function doesn’t take the String values as arguments, insatead the java.lang.String class explicitly as argument. Otherwise, this results in an error.