码迷,mamicode.com
首页 > 编程语言 > 详细

java继承

时间:2017-10-12 12:06:59      阅读:250      评论:0      收藏:0      [点我收藏+]

标签: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 }

 结果输出:

技术分享

 

java继承

标签:mon   输出   ble   继承   []   print   extends   img   ring   

原文地址:http://www.cnblogs.com/evilliu/p/7655262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!