静态变量
Static用于修饰类的成员,如成员变量、成员方法以及代码块等,被static修饰的成员具备一些特殊性
Static关键字只能用于修饰成员变量,不能用于修饰局部变量,否则编译会报错
普通方法可以调用静态方法
静态方法不可以掉头普通方法
例如:pulic static int count=0;
计算三角形的周长
package LD;
public class Person {
private static final String Sysytem = null;
private int a;
private int b;
private int c;
public Person(int a,int b,int c) {
this.a=a;
this.b=b;
this.c=c;
}
public void setA(int a) {
this.a=a;
}
public int getA() {
return a;
}
public void setB(int b) {
this.b=b;
}
public int getB() {
return b;
}
public void setC(int c) {
this.c=c;
}
public int getC() {
return c;
}
public boolean Person() {
if(a+b>c&&b+c>a&&c+a>b)
return true;
else
return false;
}
public void getLength() {
if(Person())
System.out.println(a+b+c);
else
System.out.println(“输出边长无效”);
}
}
package LD;
public class Main {
public static void main(String args[]) {
Person n=new Person(3,4,5);
n.getLength();
}
}