1. 程式人生 > >Point類的建構函式

Point類的建構函式

在這裡插入圖片描述

import java.util.*;
class Point{
	int a;
	int b;
	Point() {
		a=0;
		b=0;
	}
	Point(int a,int b) {
		this.a=a;
		this.b=b;
	}
	public void showPoint() {
		System.out.println("("+a+","+b+")");
	}
}
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		Point m=new Point();
		m.showPoint();
		int x=sc.nextInt();
		int y=sc.nextInt();
		Point n=new Point(x,y);
		n.showPoint();
		
		sc.close();
	}
}