constructor de Java
class MyClass {
public MyClass () {
//constructor code
}
}
just-saved-you-a-stackoverflow-visit
class MyClass {
public MyClass () {
//constructor code
}
}
public class ConsDemo {
public static void main(String args[]) {
MyClass t1 = new MyClass();
MyClass t2 = new MyClass();
System.out.println(t1.num + " " + t2.num);
}
}
class Person {
var children: MutableList<Person> = mutableListOf<>()
constructor(parent: Person) {
parent.children.add(this)
}
}
class Ball {
constructor(w, h) {
this.width = 100;
this.height = 100;
}
}
Constructor are a type of method
* Share the name of class
* Called when you Instantiate a Class
Default Constructor accepts no Arguments