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