
如
class A{
public static void a(){}
public void b(){}
}
public class B{
public static void main(String[] args){
A.a()//静态
new A().b()//非静态
}
}
Java创建一个类的对象通过new关键字创建:语法如下:
类 对象 = new 类构造方法();
实例:
public class Person{
String name
char sex
int age
public static void main(String[] args){
//在main方法完成Person类的对象person创建
Person person1 = new Person()
}
}
你明白了吗?
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)