{"action":"created","issue":{"url":"https://api.github.com/repos/icewaters/icewaters.github.io/issues/70","labels_url":"https://api.github.com/repos/icewaters/icewaters.github.io/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/icewaters/icewaters.github.io/issues/70/comments","events_url":"https://api.github.com/repos/icewaters/icewaters.github.io/issues/70/events","html_url":"https://github.com/icewaters/icewaters.github.io/issues/70","id":103457982,"number":70,"title":"java code","user":{"login":"icewaters","id":2446601,"avatar_url":"https://avatars.githubusercontent.com/u/2446601?v=3","gravatar_id":"","url":"https://api.github.com/users/icewaters","html_url":"https://github.com/icewaters","followers_url":"https://api.github.com/users/icewaters/followers","following_url":"https://api.github.com/users/icewaters/following{/other_user}","gists_url":"https://api.github.com/users/icewaters/gists{/gist_id}","starred_url":"https://api.github.com/users/icewaters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icewaters/subscriptions","organizations_url":"https://api.github.com/users/icewaters/orgs","repos_url":"https://api.github.com/users/icewaters/repos","events_url":"https://api.github.com/users/icewaters/events{/privacy}","received_events_url":"https://api.github.com/users/icewaters/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-27T08:47:15Z","updated_at":"2015-08-29T06:09:44Z","closed_at":null,"body":"```java\r\n/*\r\n描述小汽车\r\n1.属性\r\n\t轮胎数\r\n\t颜色\r\n2.行为\r\n\t运行\r\n*/\r\n\r\nclass Car {\r\n\r\n\tint num;\t//轮胎数\r\n\tString color; //颜色\r\n\r\n\tvoid run() {\r\n\t\t//注意这里的num虽然没有初始值，但是num变量(成员变量)是在堆里，java会自动初始化值\r\n//注意这里的num只有在创建对象时，num才会存在相应的对象里，这里类里的num只是描述\r\n\t\tSystem.out.println(num+\"...\"+color);\r\n\t}\r\n\r\n// 如果需要这个类独立运行，可以引入主函数\r\n\t/*public static void main(String[] args) {\r\n\t\tSystem.out.println(\"Hello\");\r\n\r\n\t\tCar bmw = new Car();\r\n\t\tSystem.out.println(bmw);\r\n\t\tbmw.color = \"green\";\r\n\t\tbmw.run();\r\n\t}*/\r\n}\r\n\r\nclass CarDemo {\r\n\tpublic static void main(String[] args) {\r\n\t\tint num;\r\n\t\t//注意这里的num(局部变量)没有初始值，因为是在栈里面，所以这里会报错\r\n\t\t// System.out.println(num);\r\n\t\t//内存中创建一个实体\r\n\t\tCar bmw = new Car();\r\n\t\tSystem.out.println(bmw);\r\n\t\tbmw.color = \"red\";\r\n\t\tbmw.run();\r\n\t}\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/icewaters/icewaters.github.io/issues/comments/135945865","html_url":"https://github.com/icewaters/icewaters.github.io/issues/70#issuecomment-135945865","issue_url":"https://api.github.com/repos/icewaters/icewaters.github.io/issues/70","id":135945865,"user":{"login":"icewaters","id":2446601,"avatar_url":"https://avatars.githubusercontent.com/u/2446601?v=3","gravatar_id":"","url":"https://api.github.com/users/icewaters","html_url":"https://github.com/icewaters","followers_url":"https://api.github.com/users/icewaters/followers","following_url":"https://api.github.com/users/icewaters/following{/other_user}","gists_url":"https://api.github.com/users/icewaters/gists{/gist_id}","starred_url":"https://api.github.com/users/icewaters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icewaters/subscriptions","organizations_url":"https://api.github.com/users/icewaters/orgs","repos_url":"https://api.github.com/users/icewaters/repos","events_url":"https://api.github.com/users/icewaters/events{/privacy}","received_events_url":"https://api.github.com/users/icewaters/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T06:09:44Z","updated_at":"2015-08-29T06:09:44Z","body":"```java\r\nclass Fu {\r\n\tint num = 44;\r\n\tint snum = 77;\r\n\r\n\tprivate int pp = 88;\r\n}\r\n/*\r\n当本类的成员与局部变量同名，我们使用this区分\r\n当子父类中的成员变量同名时，我们使用super区分父类\r\n\r\nthis 和 super 用法相似\r\nthis：代表一个本类对象的引用\r\nsuper：代表一个父类空间,继承过来的成员都可以使用super访问\r\n*/\r\n// Zi extend Fu ＝＝》 Zi super Fu\r\nclass Zi extends Fu {  //? 虽然子类zi中也有num，那么zi类有没有继承父类中的num ？ 继承，那该怎么访问继承过来的num\r\n\tint num = 11;\t   // 注意子类中的num并没有覆盖继承过来的num\r\n\tvoid show() {\r\n\t\tSystem.out.println(\"子类num：\" + this.num); //访问子类原有的num\r\n\t\tSystem.out.println(\"父类num：\" + super.num); //访问继承过来的num\r\n\r\n\t\tSystem.out.println(\"子类snum：\" + this.snum); //访问继承过来的snum 它会首先查找本类对象中的snum，没有就查找super中继承过来的snum\r\n\t\tSystem.out.println(\"父类snum：\" + super.snum); //访问继承过来的snum\r\n\r\n\r\n\t\t//尝试修改super.num, 不能修改父类值，只在本对象中修改\r\n\t\tsuper.num = 0;\r\n\t\tSystem.out.println(\"父类num-修改：\" + super.num);\r\n\r\n\t\t//输出this  \r\n\t\tSystem.out.println(\"zi-this: \" + this);\r\n\r\n\t\t//输出super  error\r\n\t\t//System.out.println(\"zi-super: \" + super);\r\n\r\n\t\t//访问父类私有的成员 ,子类已经继承过来了父类的私有成员，但是不能访问，只能间接访问（通过父类提供的方法）\r\n\t\t//System.out.println(\"private-pp: \" + this.pp);\r\n\t\t//System.out.println(\"private-pp: \" + super.pp);\r\n\t}\r\n}\r\n\r\nclass Son extends Fu {\r\n\tint num = 33;\r\n\tvoid showNum() {\r\n\t\tSystem.out.println(\"Son: \" + super.num);\r\n\r\n\t\t//输出super error\r\n\t\t//System.out.println(\"son-super: \" + super);\r\n\t}\r\n}\r\n\r\nclass ExtendsDemo2 {\r\n\tpublic static void main(String[] args) {\r\n\t\tZi z = new Zi();\r\n\t\tz.show();\r\n\r\n\t\tSon s = new Son();\r\n\t\ts.showNum();\r\n\t}\r\n}\r\n```"}}