- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program without making class
Is it possible to create and run a Java program without any class? The answer is Yes. Trick is to use enum instead of Class. Although enum is used to represent public static constant. It can have static main method as well. See the example below −
Example
public enum Tester { C, Java, PHP; public static void main(String[] args) { System.out.println("Programming in " + Tester.C.toString()); System.out.println("Programming in " + Tester.Java.toString()); System.out.println("Programming in " + Tester.PHP.toString()); } }
Output
Programming in C Programming in Java Programming in PHP
Advertisements