标签:mon 输出 ble 继承 [] print extends img ring
先看如下代码:
1 package com.company; 2 3 public class init_java { 4 public static void main(String[] args){ 5 Employee man=new Manager("tom",22,23000,20000); 6 Manager man1=new Manager("tom",22,23000,20000); 7 System.out.println(man.getSalary()); 8 // System.out.println(man.giveMon()); 9 System.out.println(man1.giveMon()); 10 } 11 12 13 } 14 15 16 class Employee{ 17 private int age; 18 private String name; 19 private double salary; 20 private String alaname; 21 public Employee(String aname,int aage,double asalary){ 22 this("evil"); 23 this.age=aage; 24 this.salary=asalary; 25 this.name=aname; 26 } 27 public Employee(String aname){ 28 this.alaname=aname; 29 } 30 public String getName(){ 31 System.out.println(this.name); 32 return this.name; 33 } 34 public double getSalary(){ 35 return this.salary; 36 }; 37 public String getAlaname(){ 38 return this.alaname; 39 } 40 } 41 42 43 class Manager extends Employee{ 44 private double mon; 45 public Manager(String aname,int aage,double asalary,double mon){ 46 super(aname,aage,asalary); 47 this.mon=mon; 48 } 49 public double giveMon(){ 50 double salary= super.getSalary(); 51 salary+=this.mon; 52 return salary; 53 } 54 }
结果输出:
标签:mon 输出 ble 继承 [] print extends img ring
原文地址:http://www.cnblogs.com/evilliu/p/7655262.html