Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

Program to demonstrate how Constructor works in Java ?

A Simple Java program demonstrating how a Constructor works in Java :

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 :



 
© 2021 Learn Java by Examples Template by Hubberspot