zoukankan      html  css  js  c++  java
  • 练习

    package test_02;
    
    import test_01.Person;
    import test_01.Student;
    
    class Person{
    	private String name;
    	private String location;
    	Person(String name){
    		this.name = name;
    		location ="Beijing";
    		
    	}
    	Person(String name,String location){
    		this.name = name;
    		this.location = location;
    		
    	}
    	public String info(){
    		return "name:"+name+"location:"+location;
    		
    	}
    	
    }
    class Student extends Person{
    	private String school;
    	Student(String name,String school){
    		this(name,school,"beijing");
    	}
    	Student(String n,String school,String l){
    		super(n,l);
    		this.school = school;
    	}
    	public String info() {
    		return super.info()+"school:"+school;
    		
    	}
    	
    }
    public class test_01 {
    	public static void main(String args[]) {
    		Person p1 = new Person("A");
    		Person p2 = new Person("B","shanghai");
    		Student s1 = new Student("C","S1");
    		Student s2= new Student("C","shanghai","S2");
    		System.out.println(p1.info());
    		System.out.printf(p2.info());
    		System.out.println(s1.info());
    		System.out.println(s2.info());
    		
    		
    	}
    
    }
    

      代码执行结果:

    name:Alocation:Beijing
    name:Blocation:shanghainame:Clocation:beijingschool:S1
    name:Clocation:S2school:shanghai

  • 相关阅读:
    如何进行简单画图
    缓冲技术
    信号量机制
    进程通信
    中断技术
    操作系统原理-图书主题
    供多处理器系统中的高速缓存同步中使用的转发状态
    js几种escape()解码与unescape()编码
    MySQL 元数据
    MySQL 复制表
  • 原文地址:https://www.cnblogs.com/white-the-Alan/p/10172838.html
Copyright © 2011-2022 走看看