首页 > 编程语言 > 详细

java 类的继承

时间:2019-12-21 11:34:54      阅读:86      评论:0      收藏:0      [点我收藏+]

 

package testpacknm;

import java.util.Scanner;
import testpacknm.testcnm;

class Another {
    String name;
}

public class testcnm extends Another {
    int salary;

    public static void main(String[] args){
        testcnm obj = new testcnm();
        obj.salary = 10000;
        obj.name = "Prakash";
        System.out.println("Name: " + obj.name);
        System.out.println("Salary: " + obj.salary);
    }

}

 2

package testpacknm;

import java.util.Scanner;
import testpacknm.testcnm;


class Salary extends Details {
    public void SalaryMethod() {
        System.out.println("Calling the salary method");
    }
}

class Details {
    public void detailMethod() {
        System.out.println("Calling detail method");
    }
}

public class testcnm {
    public static void main(String[] args) {
        Salary sal = new Salary();
        sal.detailMethod();
        sal.SalaryMethod();
    }
}

 

java 类的继承

原文:https://www.cnblogs.com/sea-stream/p/12076029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!