Java Constructor
In this post we will learn how to create constructor in Java.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
In this post we will learn how to create constructor in Java.
class DemoClass {
public int constructor1;
public String constructor2;
DemoClass(int constructor1) {
this.constructor1 = constructor1;
}
DemoClass(String constructor2) {
this.constructor2 = constructor2;
}
}
public class Main {
public static void main(String[] args) {
DemoClass demoClass1 = new DemoClass(1);
DemoClass demoClass2 = new DemoClass("Demo");
}
}
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment