How to Create Multiple Objects of a Class in Java


In this example, we will learn you how to create multiple objects of a class in Java.

Source Code

package com.beginner.examples;

public class MultipleObjects {
  int i = 1;

  public static void main(String[] args) {
    // create multiple objects of a class
    MultipleObjects a = new MultipleObjects();
    MultipleObjects b = new MultipleObjects();
    System.out.println(a.i);
    System.out.println(b.i);
  }
}

Output:

1
1
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments