public class Test {
/**
* Initial Learning for Java classes:
* Learn to use the same two construction methods as the class name to invoke the public class method:
*/
public static void Main (string[] args) {
Point point = new Point (100,27);
Note: Methods for printing objects
System.out.print (point);//Why does it not call the ToString method?
System.out.print (Point.tostring ()); can also be output normally
}
}
Class Point {
private int x = 0;
private int y = 0;
/*
* Two methods of construction:
* Note: The method of constructing the call itself is with this (xxx,xxx,...) To complete and must be on the first line.
*/
For two formal parameters
public point (int x, int y) {
this.x = x;
This.y = y;
}
For two formal parameters
public point (int x) {
This (x, x); Two values are the same at a formal parameter
}
Public String toString () {
Return "(x:" + this.x + ", y:" + this.y + ")";
}
}
Java class initialization, using construction methods