myclass.java

来自「java的oop编程important example」· Java 代码 · 共 31 行

JAVA
31
字号
// This shows off the uses of this 

// This shows off the uses of "this". It is a non-public class
// just so the file name UseThis doesn't have to be the class name
// (some students found "This" in the class name confusing in this example).
public class MyClass {
  final static int MAXX=640, MAXY=480;  // low-res (VGA)
  int x, y;        // current location
  /** Construct a MyClass with x and y values */
  MyClass(int x, int y) {
    this.x = x;
    this.y = y;
        }
  /** Construct a MyClass with default values */
  MyClass() {
    this(MAXX/2, MAXY/2);   // Use the constructor above
        }

  public String toString() {
    return "[" + x + "," + y + "]";
  }

  /** Test main program */
  public static void main(String[] av) {
    System.out.println(new MyClass(300,100));
    System.out.println(new MyClass());
  }
}  
 
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?