zoukankan      html  css  js  c++  java
  • 动手动脑 类与对象

    class Grandparent 
    {
        public Grandparent()
         {
                System.out.println("GrandParent Created.");
        
    }
        public Grandparent(String string) 
        {
                System.out.println("GrandParent Created.String:" + string);
     }
    }
    class Parent extends Grandparent
    {
        public Parent()
         {
                //super("Hello.Grandparent.");
                System.out.println("Parent Created");
           // super("Hello.Grandparent.");
          }
    }
    class Child extends Parent 
    {
        public Child()
         {
            System.out.println("Child Created");
          }
    }
    public class TestInherits 
    {
        public static void main(String args[])
         {
                Child c = new Child();  
      }
    }
    package o;
    public class ParentChildTest {
        public static void main(String[] args) {
            Parent parent=new Parent();
            parent.printValue();
            Child child=new Child();
            child.printValue();
             
            parent=child;
            parent.printValue();
             
            parent.myValue++;
            parent.printValue();
             
            ((Child)parent).myValue++;
            parent.printValue();       
        }
    }
    class Parent{
        public int myValue=100;
        public void printValue() {
            System.out.println("Parent.printValue(),myValue="+myValue);
        }
    }
    class Child extends Parent{
        public int myValue=200;
        public void printValue() {
            System.out.println("Child.printValue(),myValue="+myValue);
        }
    }
  • 相关阅读:
    python3 day02 大纲
    python3 练习题 day02
    python3 练习题(购物车)
    python3 练习题(多级菜单)
    python3 day01 大纲
    python3 练习题 day01
    vuex 的基本使用
    jquery中Ajax使用Promise指定成功回调函数
    使用Promise 解决回调地狱
    Promise 概念及操作
  • 原文地址:https://www.cnblogs.com/xiatian21/p/11788679.html
Copyright © 2011-2022 走看看