A Simple Java program demonstrating how a Constructor works in Java :
Output of the program :
package com.hubberspot.objects.example; class IPL { IPL() { // Constructor System.out.println("This season's IPL teams are :"); System.out.println("1. Deccan Chargers"); System.out.println("2. Kolkata Night Riders"); System.out.println("3. Mumbai Indians"); System.out.println("4. Chennai Super Kings"); System.out.println("5. Rajasthan Royals"); System.out.println("6. Royal Challengers Bangalore"); System.out.println("7. Kings XI Punjab"); System.out.println("8. Pune Warriors India"); System.out.println("9. Delhi Daredevils"); } } public class SimpleConstructor { public static void main(String[] args) { new IPL(); } }
Output of the program :