面向对象1

在内存中创建对象

对象都是储存在堆中,然后在栈中储存局部变量,这个变量的储存的值就是想要的堆内存的地址

 

public class Dog {

String name;
String type;
String xingBie;
public void lookHome(){
System.out.println(name + "正在看家");
}
public void info(){                //哪个对象调用这个方法,那么里边属性就是这个对象的属性
System.out.println("姓名:"+ name + "种类:"+ type + "性别: "+ xingBie);
}
public static void Number(int a,int b,int c){
if(a>b && a > c){
System.out.println(a);
}else if(b > a && b >c){
System.out.println(b);
}else{
System.out.println(c);
}
}
public static void main(String[] args) {
Dog dog = new Dog();
dog.name = "小黄";
dog.type = "哈士奇";
dog.xingBie = "公的";
dog.lookHome();
dog.info();
Dog dog1 = new Dog();
dog1.name = "blot";
dog1.type = "超人狗";
dog1.xingBie = "母的";
dog1.lookHome();
int num1 = 5,
num2 = 7,
num3 = 1;
Number(num1, num2, num3);
}

}

posted @ 2019-01-09 11:15  啸逸  阅读(91)  评论(0编辑  收藏  举报