`
standalone
  • 浏览: 613014 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Overriding Method Using Parameter That is a Subclass?

    博客分类:
  • java
阅读更多
参见 http://www.coderanch.com/t/389279/java/java/Overriding-Method-Parameter-Subclass

本来想用汉语写标题,发现实在不好说这个逻辑。。。

好吧,这个问题的答案是“这是overload不是override”。

可以参考一下程序验证:
public class Animal {
	public void talkTo(Animal a){
		System.out.println("animal");
	}
}


public class Cat extends Animal {
	public void talkTo(Cat c){
		System.out.println("Cat");
		super.talkTo(c);
	}
	public static void main(String [] args){
		Cat c = new Cat();
		Animal a = new Animal();
		c.talkTo(a);		
		c.talkTo(c);
	}
}

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    Softgroup Components.NET Subclass and Hook Objects v2.0.3870

    However, to wrap subclassing and hooking into virtual function overriding it is an obscure technique unknown to a large population of Windows programmers. This is unfortunate, because there are many ...

    java面试题英文版及其答案

    Method overriding allows a subclass to provide a different implementation for a method defined in its superclass, while method overloading involves having multiple methods with the same name but ...

    Spring Boot: Bean definition overriding

    在本文中,我将讨论棘手的Spring Boot bean定义覆盖机制。 为了使您对该主题更加清楚,让我们从小测验开始。请看下一个简单的例子。 因此,我们有2种配置,它们使用名称beanName实例化bean,在主应用程序中,我们仅...

    微软内部资料-SQL性能优化3

    For example, if T1 writes some object that is in T2’s input or output set, there is a dependency between T1 and T2. Bad Dependencies These include lost updates, dirty reads, non-repeatable reads, ...

    android @override 报错解决方案

    现象: … java: 1801: method does not override a method from its superclass @Override… 原因: Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 ...

    Lerner -- Python Workout. 50 Essential Exercises -- 2020.pdf

    - Using the `*args` parameter to accept variable arguments. - Type checking to ensure compatibility. - Using the `sum()` function. 11. **Alphabetizing Names** - **Objective:** Sort a list of ...

    coreJava240问与答面试题

    3) What is method overriding in java ? ........................................................................................ 9 4) What is super keyword in java ? ......................................

    Overloading&Overriding

    "Overloading&Overriding" 在面向对象编程中,Overloading和Overriding是两个重要的概念,它们都是多态性的体现。下面我们将对这两个概念进行详细的解释。 1. 方法重载(Overloading) 方法重载是让类以统一的...

    1Z0-811 Exam Guide to Have a Cakewalk in Oracle Java SE Certific

    - **Overloading and Overriding:** Learn about method overloading and overriding. 3. **Decision Statements:** - **If-Else Statements:** Master the use of if-else statements for conditional logic. -...

    methodmethodmethod

    标题中的"methodmethodmethod"可能是指在编程领域中关于方法(Method)的概念,这通常与面向对象编程语言相关。方法是类(Class)中的一个函数,它定义了该类对象可以执行的操作。在Java、C#、Python等语言中,方法是...

    Problem Solving with C++ (7th edition)

    In this chapter, the focus is on understanding the process of creating a C++ program from start to finish. The key points covered include: - **Introduction to the C++ Compiler**: Explanation of what ...

    cJSON-master.zip

    That page inspired me to write cJSON, which is a parser that tries to share the same philosophy as JSON itself. Simple, dumb, out of the way. ### Building There are several ways to incorporate ...

    PROFESSIONAL F# 2.0

    - **Pattern Matching (Chapter 6):** Pattern matching is a powerful feature of F# that allows for concise and expressive code. This chapter explains how to use pattern matching to deconstruct data ...

    Method-Overloading-and-OverRiding.rar_OA系统_Java_

    在Java编程语言中,"方法重载(Method Overloading)"和"方法重写(Method Overriding)"是两个核心概念,它们都是实现多态性的重要方式,而在OA(Office Automation)系统开发中,理解并熟练运用这两个概念是至关...

    ZendFramework中文文档

    Querying if the input is valid 14.5.3.2. Getting Invalid, Missing, or Unknown Fields 14.5.3.3. Getting Valid Fields 14.5.4. Using Metacommands to Control Filter or Validator Rules 14.5.4.1. The ...

    TRotateImage v1.4 (图像旋转)

    TRotateImage v1.4 是一个专为DELPHI开发者设计的组件,它允许用户以任意角度对图像进行旋转操作。这个组件扩展了TGraphicControl类,提供了在应用程序中直观且高效地处理图像旋转的能力。TGraphicControl是VCL框架...

Global site tag (gtag.js) - Google Analytics