
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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
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.
- Related Articles
- Can we define a method name same as class name in Java?
- Why the constructor name is same as the class name in Java?
- What is the difference between simple name, canonical name and class name in a Java class?
- Why the java file name should be always the same as a public class name?
- Get Canonical Name for a class in Java
- Should a constructor always have the same name as the class in java?
- Display the package name of a class in Java
- Get the unqualified name of a class in Java
- Get the class name for various objects in Java
- How to get css class name using Selenium?
- How to implement an instance method reference using a class name in Java?
- Can a method have the same name as the class?
- How to access the object of a class without using the class name from a static context in java?
- Get the fully-qualified name of a class in Java
- Get the fully-qualified name of an inner class in Java

Advertisements