文章标题
2016-04-14 20:31
323 查看
person类的继承(student类)以及成员函数getInfo函数的重写。
package com.第三章lab;
class person1{
public String name;
public int age;
public person1(String name,int age){
this.name=name;
this.age=age;
}
public person1(){
}
class Student extends person1{
public String school;
public Student (String name,int age,String school){
super.name=name;
super.age=age;
this.school=school;
}
public Student(){
}
public class person{
public static void main(String[] args){
Student s1=new Student();
s1.name=”lxp”;
s1.age=3;
s1.school=”JXNU”;
s1.Study();
s1.getInfo();
}
}
package com.第三章lab;
class person1{
public String name;
public int age;
public person1(String name,int age){
this.name=name;
this.age=age;
}
public person1(){
} public void getInfo(){ System.out.println(name); System.out.println(age); }
}
class Student extends person1{
public String school;
public Student (String name,int age,String school){
super.name=name;
super.age=age;
this.school=school;
}
public Student(){
} public void Study(){ System.out.println(name+" is studing!"); } public void getInfo(){ super.getInfo(); System.out.println(school); }
}
public class person{
public static void main(String[] args){
Student s1=new Student();
s1.name=”lxp”;
s1.age=3;
s1.school=”JXNU”;
s1.Study();
s1.getInfo();
}
}
相关文章推荐
- JAVA实现有理数的运算+JAVA中的适配器模式
- 堆排序
- poj 【1321】
- PAT1045 Favorite Color Stripe
- varchar2(n)与varchar2(n char)的区别
- 0414 复利计算再升级
- 纯CSS实现帅气的SVG路径描边动画效果(转载)
- BZOJ 3993 SDOI2015 星际战争
- C++中 vector、list、deque、set、map的底层实现
- Uva 442 Matrix Chain Multiplication
- 包图
- 面试某公司前端关于javascript中this的总结
- java编程中常见的异常
- 20145201 实验二 Java面向对象程序设计
- Glide和Picassio的比较
- Web防止请求过于频繁的一种方法
- 4pardim+360
- POJ题目分类
- extern声明全局变量的一些用法
- 解决打印机报错:操作无法完成(错误0x00000709)。