regarding a method definition in a class

user288609

I have a question regarding the class definition in Java. With respect to the following code segment, after the if switch already verifies that h is an instance of Animal, why we still need to add the line of Animal ob = (Animal) h? In addition, why the second coding segment is wrong? I know it should come from the line of public boolean equals (Animal h)

enter image description here

enter image description here

KSFT

Object.equals() takes an object of type Object, so the second example is wrong because it takes an Animal object instead. In the first one, the cast is because the variable has type Object, even though it actually is an instance of the Animal type, so it needs to be cast to be assigned to a variable of type Animal.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Dynamic method definition in a class

From Dev

Regarding EasyMock for class that contains method with parameters

From Dev

Ruby: class definition in method body

From Dev

Overriding a class's method definition

From Dev

Implementation after class method definition

From Dev

Definition of "handle" regarding DLLs

From Dev

inner class method definition outside of a template class

From Dev

Soap service method class definition c#

From Dev

TypeScript - How to add a method outside the class definition

From Dev

Reference instance method outside class definition

From Dev

Method definition need to use private declaration of a class

From Dev

Explicit use of `self` in method name in class definition

From Dev

TypeScript - How to add a method outside the class definition

From Dev

´class´ does not contains a definition for ´method´ but it´s there

From Dev

Python - declare method name in dictionary with method definition in outside class

From Dev

Python - declare method name in dictionary with method definition in outside class

From Dev

PHP Combine Class Definition & Class Method Call into one line

From Dev

How can one use a class method in a class attribute definition

From Dev

Confusion regarding Overriding toString() method in a Class(Data class or POJO) and calling list.toString()?

From Java

What does the "has" keyword mean before "method" in a Raku class definition?

From Java

How can I jump to class/method definition in Atom text editor?

From Dev

Why must a method be declared in a C++ class definition?

From Dev

Move method definition for template nested class outside declaration

From Dev

Including header files in C++ (class definition and method implementation)

From Dev

Why can't I override the method definition in the class(function) description?

From Dev

how to call deinit method within class definition in swift

From Dev

double-colon (::) before method declaration in class definition

From Dev

Definition of pure virtual method while using templated class with sfinae

From Dev

C++ public method definitions after class definition?

Related Related

  1. 1

    Dynamic method definition in a class

  2. 2

    Regarding EasyMock for class that contains method with parameters

  3. 3

    Ruby: class definition in method body

  4. 4

    Overriding a class's method definition

  5. 5

    Implementation after class method definition

  6. 6

    Definition of "handle" regarding DLLs

  7. 7

    inner class method definition outside of a template class

  8. 8

    Soap service method class definition c#

  9. 9

    TypeScript - How to add a method outside the class definition

  10. 10

    Reference instance method outside class definition

  11. 11

    Method definition need to use private declaration of a class

  12. 12

    Explicit use of `self` in method name in class definition

  13. 13

    TypeScript - How to add a method outside the class definition

  14. 14

    ´class´ does not contains a definition for ´method´ but it´s there

  15. 15

    Python - declare method name in dictionary with method definition in outside class

  16. 16

    Python - declare method name in dictionary with method definition in outside class

  17. 17

    PHP Combine Class Definition & Class Method Call into one line

  18. 18

    How can one use a class method in a class attribute definition

  19. 19

    Confusion regarding Overriding toString() method in a Class(Data class or POJO) and calling list.toString()?

  20. 20

    What does the "has" keyword mean before "method" in a Raku class definition?

  21. 21

    How can I jump to class/method definition in Atom text editor?

  22. 22

    Why must a method be declared in a C++ class definition?

  23. 23

    Move method definition for template nested class outside declaration

  24. 24

    Including header files in C++ (class definition and method implementation)

  25. 25

    Why can't I override the method definition in the class(function) description?

  26. 26

    how to call deinit method within class definition in swift

  27. 27

    double-colon (::) before method declaration in class definition

  28. 28

    Definition of pure virtual method while using templated class with sfinae

  29. 29

    C++ public method definitions after class definition?

HotTag

Archive