首页 > 编程语言 > 详细

java 继承

时间:2017-11-25 12:54:28      阅读:222      评论:0      收藏:0      [点我收藏+]
父类


public class person {
	 String name;
	 int age;
	 void eat(){
		 System.out.println("吃饭");
	 }
	 void introduce(){
		 System.out.println("我的名字是"+name +",我的年龄是"+age);
	 }
	 
}

  

子类

public class testper extends person {
    int grade;
    void study(){
        System.out.println("学习,年级是"+this.grade);
    }
}
测试下继承

public class ss {
public static void main(String[] args){
        testper testper=new testper();
        testper.grade=1;
        testper.name="北京";
        testper.age=10;
        testper.eat();
        testper.introduce();
        testper.study();
    }
}

 

输出

技术分享图片

java的继承只能是单继承。

java 继承

原文:http://www.cnblogs.com/leiziv5/p/7894830.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!