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

  • 相关阅读:
    git环境搭建、git详细使用教程、快速上手git
    数据一致性解决方案实践
    锁的使用
    数据库连接池优化
    多级缓存优化实践
    服务端调优与JVM调优
    Sentinel 流量防卫兵
    Spring Cloud Gateway微服务网关
    OpenFeign与负载均衡
    Nacos config原理
  • 原文地址:https://www.cnblogs.com/white-the-Alan/p/10172838.html
Copyright © 2011-2022 走看看