吴裕雄--天生自然JAVA面向对象高级编程学习笔记:继承的应用
class Array{ // 表示数组
private int temp[] ; // 整型数组
private int foot ; // 定义添加位置
public Array(int len){
if(len>0){
this.temp = new int[len] ;
}else{
this.temp = new int[1] ; // 最少维持空间是1个
}
}
public boolean add(int i){ // 增加元素
if(this.foot<this.temp.length){ // 还有空间
this.temp[foot] = i ; // 增加元素
this.foot ++ ;// 修改脚标
return true ;
}else{
return false ;
}
}
public int[] getArray(){
return this.temp ;
}
};
class SortArray extends Array{ // 排序类
public SortArray(int len){
super(len) ;
}
public int[] getArray(){ // 覆写方法
java.util.Arrays.sort(super.getArray()) ; // 排序操作
return super.getArray() ;
}
};
class ReverseArray extends Array{ // 反转操作类
public ReverseArray(int len){
super(len) ;
}
public int[] getArray() {
int t[] = new int[super.getArray().length] ; // 开辟一个新的数组
int count = t.length - 1 ;
for(int x=0 ;x<t.length;x++){
t[count] = super.getArray()[x] ; // 数组反转
count-- ;
}
return t ;
}
};
public class ArrayDemo{
public static void main(String args[]){
// ReverseArray a = null ; // 声明反转类对象
// a = new ReverseArray(5) ; // 开辟5个空间大小
SortArray a = null ;
a = new SortArray(5) ;
System.out.print(a.add(23) + "\t") ;
System.out.print(a.add(21) + "\t") ;
System.out.print(a.add(2) + "\t") ;
System.out.print(a.add(42) + "\t") ;
System.out.print(a.add(5) + "\t") ;
System.out.print(a.add(6) + "\t") ;
print(a.getArray()) ; }
public static void print(int i[]){ // 输出数组内容
for(int x=0;x<i.length;x++){
System.out.print(i[x] + "、") ;
}
}
};
吴裕雄--天生自然JAVA面向对象高级编程学习笔记:继承的应用的更多相关文章
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:匿名内部类
interface A{ public void printInfo() ; // } class B implements A{ // 实现接口 public void printInfo(){ S ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:包装类
public class WrapperDemo01{ public static void main(String args[]){ int x = 30 ; // 基本数据类型 Integer i ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:Object类
class Demo{ // 定义Demo类,实际上就是继承了Object类 }; public class ObjectDemo01{ public static void main(String ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:宠物商店实例分析
interface Pet{ // 定义宠物接口 public String getName() ; public String getColor() ; public int getAge() ; ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:抽象类与接口的应用
abstract class A{ // 定义抽象类A public abstract void print() ; // 定义抽象方法print() }; class B extends A { / ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:instanceof关键字
class A{ // 定义类A public void fun1(){ // 定义fun1()方法 System.out.println("A --> public void fun ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:对象的多态性
class A{ // 定义类A public void fun1(){ // 定义fun1()方法 System.out.println("A --> public void fun ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:接口的基本实现
interface A{ // 定义接口A public static final String AUTHOR = "李兴华" ; // 全局常量 public abstract ...
- 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:final关键字
final class A{ // 使用final定义类,不能有子类 }; class B extends A{ // 错误,不能被继承 }; class A{ public final void p ...
随机推荐
- C语言-(void*)类型指针
(void*)类型指针:ANSI新增的:即定义了一个指针,但不指定指向任何类型(即指向抽象的数据类型). 1 通过强制类型转换可将其值赋给另一指针变量 2.1用于动态存储函数的返回型指针 void m ...
- POJ 1064 Cable master(二分答案)
嗯... 题目链接:http://poj.org/problem?id=1064 其实这是一道很好想的二分答案的一道题... 二分的区间就是1~max_l,从1开始是因为所有小于1的都需要按0计算,没 ...
- 「AT4741 [ABC132D] Blue and Red Balls」
题目大意 给出一个长度为 \(N\) 的01串,其中有 \(K\) 个 \(1\),其他都是 \(0\),需要求出当着 \(K\) 个 \(1\) 分成 \(1\) 到 \(K\) 段每一个的方案数. ...
- how to analyze jmeter results
https://octoperf.com/blog/2017/10/19/how-to-analyze-jmeter-results/
- python笔记14
今日内容 带参数的装饰器: flask框架 + django缓存 + 写装饰器实现被装饰的函数要执行N次 模块 os sys time(三种类型) datetime 和 timezone[了解] 内容 ...
- Kali 2020.1 默认密码不是toor
官方2020年一月28日的文章中指出root/toor is dead. Long live kali/kali. 登录用户名和密码是kali:kali 但是虚拟机镜像下载页面没有及时更新,仍然提示登 ...
- selenium webdriver 实现百度贴吧自动签到
public static void main(String[] args) { //TestUtils.killProcess("javaw.exe"); TestUtils.k ...
- Vim 入门使用
参考资料:https://www.runoob.com/linux/linux-vim.html 本篇内容不全,其余内容请参考该链接 vim/vi 是Linux下常用的文本编辑工具,它基本上有三种 ...
- Java 调用系统系统可执行文件
public class Test { public static Map<String, String> executeCmd(String cmd) { Runtime rt = Ru ...
- Codeforces Round #588 (Div. 2)D(思维,多重集)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[7007],b[700 ...