zoukankan      html  css  js  c++  java
  • Java学习第一周

    第一周学习了JDK的安装和环境的配置,初步了解了Java与C的不同之处,学习了Java的变量、基本数据类型、以及面向对象的基础。并且自行完成了一些简单Java程序的编写。

    (1)学习了为什么使用抽象类,使用抽象类是为了让程序员在继承时不会忘记复写,

    abstract class Printer

     {  

          void open()

          {   

              System.out.println("open ");

          }  

          void close()

         {  

              System.out.println("close");

         }    

          abstract void print();//使用 抽象 能使得程序员不会忘记复写,否则将会出错 }

         class HPPrinter extends Printer

        {  

            void print()  // 使用抽象类时这是必须复写的,否则将会报错

            {  

                 System.out.println("使用喷墨打印机");  

             }

       }

         class CannonPrinter extends Printer

          {  

              void print()  // 使用抽象类时这是必须复写的,否则将会报错  

                {  

                     System.out.println("使用针式打印机");  

                 }

      }

          class Test

          {

               public static void main(String args[])

              {

                   Printer p1 = new HPPrinter(); // 向下转移

                   p1.open();  

                   p1.close();   

                   p1.print();      

                   Printer p2 = new CannonPrinter(); // 向下转移  

                   p2.open();  

                   p2.close();  

                   p2.print();  

             }     

      }

    (2) 学习了父类 子类的调用  尽量把子类的函数都归于父类中,调用时方便,也便于随时修改

       class Printer

       {

          void open()

          {  

              System.out.println("open ");  

          }  

         void close()

         {   

             System.out.println("close");

         }    

        void print(String s)  

        {   

            System.out.println("print->" + s);  

        }

    }

    class HPPrinter extends Printer

    {  

    }

    class CannonPrinter extends Printer

    {    

        void close()  

        {   

           this.clean();  

           super.close();

        }    

       void clean()

       {   

           System.out.println("clean");

       }

    }

    class Text

    {  

       public static void main(String args[])

      {

         int flag = 1;   

         if(flag == 0)  

        {    

           HPPrinter hpPrinter = new HPPrinter();  

           hpPrinter.open();  

           hpPrinter.print("abc");   

           hpPrinter.close();   

        }   

    else if(flag == 1) 

       {    

         CannonPrinter cannonPrinter = new CannonPrinter();  

         cannonPrinter.open();  

         cannonPrinter.print("abc");   

         cannonPrinter.close();    

        }     

      }

    }

  • 相关阅读:
    root用户没有权限编辑其他用户处理
    php中 被遗忘的函数
    erlang file操作(IO编程)
    Linux下的MySQL自动备份脚本
    这就是传说中让理科生沉默,让文科生落泪的文理综合体(转)
    LINUX 忘记root密码
    php中 被遗忘的函数
    分页显示的常用操作方法
    php 接口类:interface
    php垃圾回收机制分析
  • 原文地址:https://www.cnblogs.com/zengjiqiang/p/5375268.html
Copyright © 2011-2022 走看看