吴裕雄--天生自然 JAVA开发学习:重写(Override)与重载(Overload)
class Animal{
public void move(){
System.out.println("动物可以移动");
}
}
class Dog extends Animal{
public void move(){
System.out.println("狗可以跑和走");
}
}
public class TestDog{
public static void main(String args[]){
Animal a = new Animal(); // Animal 对象
Animal b = new Dog(); // Dog 对象
a.move();// 执行 Animal 类的方法
b.move();//执行 Dog 类的方法
}
}
class Animal{
public void move(){
System.out.println("动物可以移动");
}
}
class Dog extends Animal{
public void move(){
System.out.println("狗可以跑和走");
}
public void bark(){
System.out.println("狗可以吠叫");
}
}
public class TestDog{
public static void main(String args[]){
Animal a = new Animal(); // Animal 对象
Animal b = new Dog(); // Dog 对象
a.move();// 执行 Animal 类的方法
b.move();//执行 Dog 类的方法
b.bark();
}
}
class Animal{
public void move(){
System.out.println("动物可以移动");
}
}
class Dog extends Animal{
public void move(){
super.move(); // 应用super类的方法
System.out.println("狗可以跑和走");
}
}
public class TestDog{
public static void main(String args[]){
Animal b = new Dog(); // Dog 对象
b.move(); //执行 Dog类的方法
}
}
public class Overloading {
public int test(){
System.out.println("test1");
return 1;
}
public void test(int a){
System.out.println("test2");
}
//以下两个参数类型顺序不同
public String test(int a,String s){
System.out.println("test3");
return "returntest3";
}
public String test(String s,int a){
System.out.println("test4");
return "returntest4";
}
public static void main(String[] args){
Overloading o = new Overloading();
System.out.println(o.test());
o.test(1);
System.out.println(o.test(1,"test3"));
System.out.println(o.test("test4",1));
}
}
吴裕雄--天生自然 JAVA开发学习:重写(Override)与重载(Overload)的更多相关文章
- 吴裕雄--天生自然 JAVA开发学习:变量类型
public class Variable{ static int allClicks=0; // 类变量 String str="hello world"; // 实例变量 pu ...
- 吴裕雄--天生自然 JAVA开发学习:java使用Eclipel连接数据库
1:jar可到Mysql官网下载:地址Mysql 连接jar包.:https://dev.mysql.com/downloads/connector/j/如图,在下拉列表框中选择Platform In ...
- 吴裕雄--天生自然 JAVA开发学习:解决java.sql.SQLException: The server time zone value报错
这个异常是时区的错误,因此只你需要设置为你当前系统时区即可,解决方案如下: import java.sql.Connection ; import java.sql.DriverManager ; i ...
- 吴裕雄--天生自然 JAVA开发学习:基础语法
package test; public class temp { /* 第一个Java程序 * 它将打印字符串 Hello World */ public static void main(Stri ...
- 吴裕雄--天生自然 JAVA开发学习:Scanner 类
import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanne ...
- 吴裕雄--天生自然 JAVA开发学习:流(Stream)、文件(File)和IO
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //使用 BufferedReader 在控制台读取 ...
- 吴裕雄--天生自然 JAVA开发学习:方法
/** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) re ...
- 吴裕雄--天生自然 JAVA开发学习:正则表达式
import java.util.regex.*; class RegexExample1{ public static void main(String args[]){ String conten ...
- 吴裕雄--天生自然 JAVA开发学习:日期时间
import java.util.Date; public class DateDemo { public static void main(String args[]) { // 初始化 Date ...
随机推荐
- Egret Engine 2D - Get Started
Get Started Egret 也支持在命令行完成编译,运行,发布等操作.在下面的教程中会穿插对应操作的命令行代码. 可新建游戏项目,也可建eui项目 这里包含默认的几个库,egr ...
- invisble
不可见索引概念: 不可见索引(Invisible Index)是ORACLE 11g引入的新特性.不可见索引是会被优化器忽略的不可见索引,除非在会话或系统级别上将OPTIMIZER_USE_INVIS ...
- 分享几个IntelliJ IDEA 2019 jihuo码(pojie码、zhuce码),亲测可用
文章转载自:https://www.jiweichengzhu.com/article/eb340e382d1d456c84a1d190db12755c 如果还有问题,加群交流:686430774(就 ...
- Mybatis报错——Mapped Statements collection already contains value for
解决办法: 看看你的mybatis-config.xml <mappers> <mapper resource="mapper/SeckillDao.xml&quo ...
- React + umi +antd+antv/g6 实现力图
官方示例效果:http://antv.alipay.com/zh-cn/g6/2.x/demo/net/2017-link-data.html 改编效果: 实现步骤: 环境:nodejs.yarn/n ...
- linux_c_udp_example
udp_server #include <stdlib.h> #include <string.h> #include <unistd.h> #include &l ...
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- win10编译zlib
zlib是一个数据压缩库,官网的解释很酷: A Massively Spiffy Yet Delicately Unobtrusive Compression Library(Also Free, N ...
- 关于mysql/apache/nginx的配置文件配置
2015.5.12 mysql中可以通过函数查看用户列表/查看当前用户以及删除用户,方法百度之,忘了 /etc/php5/fpm/php.ini memory_limit修改之前为128M apach ...
- 面试题:你使用过concurrent包下的那些类?
1.executor接口,使用executor接口的子接口ExecutorService用来创建线程池2.Lock接口下的ReentrantLock类,实现同步,比如三个线程循环打印ABCABCABC ...