Using predefined class name as Class or Variable name in Java


Using a predefined class name as a class name

Let us see an example −

Example

 Live Demo

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

 Live Demo

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.

Updated on: 09-Jul-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements