类,对象,方法的使用
生活随笔
收集整理的這篇文章主要介紹了
类,对象,方法的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*****
* 定義一個類,描述圓的特性
* @author yanlong
* 2017/5/5
*/
package java4;
public class liti4_1 {
private int x;
private int y;
private static int r;
public int getR() {
return r;//獲取半徑
}
public void setR(int r) {
this.r = r;
}
public float getArea(){
return (float)Math.PI*r*r;
}
public static void main(String[] aargs){
//初始化一個圓
liti4_1 a=new liti4_1();
a.x=10;
a.y=10;
a.setR(2);
float Area=a.getArea();
System.out.println("圓的半徑:"+r);
System.out.printf("圓的面積"+Area);
}
}
?
轉載于:https://www.cnblogs.com/chenyanlong/p/6814626.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的类,对象,方法的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: phpcms 前台模板替换成官网类型的
- 下一篇: webstorm git 怎么断开版本控