zoukankan      html  css  js  c++  java
  • 基类和派生类小程序2--简单

    class Person1

    {

      protected String name;

      protected int age;

      public Person1(String name,int age)

      {

        this.name=name;

        this.age=age;

      }

      protected void show()

      {

        System.out.println("姓名:"+name+"   年龄:"+age);

      }

    }

    class Student1 extends Person1

    {

      private String department;

      public Student1(String name,int age,String dep)

      {

        super(name,age);

        department=dep;

      }

      public void show()

      {

        System.out.println("系别:"+department);

      }

      public void subshow()

      {

        System.out.println("我在子类中!");

      }

    }

    public class App8_4 {

      public static void main(String []args)

      {

        Person1 per=new Student1("李强",20,"管理");

        Student1 stu=new Student1("王永涛",24,"电子");

        stu.show();

        stu.subshow();

      }

    }

  • 相关阅读:
    python常用模块②
    python常用模块①
    面向对象相关部分双下划线方法补充
    面向对象进阶 上
    面向对象初识④
    面向对象初识③
    综合架构-负载均衡
    wecent 搭建
    综合架构--存储
    综合架构--备份
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11133948.html
Copyright © 2011-2022 走看看