How to Create a Class Constructor in Java


In this example we will show you how to create a class constructor in Java.

Source Code

package com.beginner.examples;

public class ClassConstructor {
  int i;

  // Create a class constructor
  public ClassConstructor() {
    i = 11;
  }

  public static void main(String[] args) {
    ClassConstructor c = new ClassConstructor();
    System.out.println(c.i);
  }
}

Output:

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