首页 技术 正文
技术 2022年11月9日
0 收藏 531 点赞 5,052 浏览 1271 个字

第一周学习了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();

}

}

}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297