zoukankan      html  css  js  c++  java
  • _java基础_类和对象—4

    创建一个Point类,有成员变量x,y,方法getX(),setX(),还有一个构造方

    法初始化x和y。创建类主类A来测试它。

    public class Point {
    	//创建一个Point类,有成员变量x,y,方法getX(),setX(),还有一个构造方
    	//法初始化x和y。创建类主类A来测试它。
    	int x,y;
    	public int getX() {
    		return x;
    	}
    	public void setX(int x) {
    		this.x = x;
    	}
        public int getY() {
    		return y;
    	}
    	public void setY(int y) {
    		this.y = y;
    	}
    	
    	public Point(int x, int y) {
    		super();
    		this.x = x;
    		this.y = y;
    	}
    	public static void main(String[] args) {
    		// TODO 自动生成的方法存根
    		Point p=new Point(3,5);
    		System.out.println(p.x+""+p.y);
    		p.setX(5);
    		p.setY(7);
    		System.out.println(p.getX()+""+p.getY());
    
    	}
    
    }
    

     

  • 相关阅读:
    ERROR: epmd error for host "yourhostname": timeout
    leetcode485
    leetcode463
    leetcode496
    leetcode344
    leetcode412
    leetcode500
    leetcode476
    leetcode557
    leetcode461
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5512591.html
Copyright © 2011-2022 走看看