File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Parent class -> Child class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Parent class -> Child class " Watch "Parent class -> Child class " New topic
Author

Parent class -> Child class

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1372
class A {

public static String meth1(int a) {

}
}


class B extends A{

public static String meth1(int a, int b) {

}
}

meth1 is not overrided method in Parent and Child classes. Whether meth1 will be considered sepate method in parent class and child class ?

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Overriding methods signature[name & parameter] must be same . if that methods are static then it is not consider as Override instead it consider as redifined .

Coming to your question, yes it is consider as a seperate method

Hope this helps you
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
seetharaman venkatasamy wrote: if that methods are static then it is not consider as Override instead it consider as redifined .

Coming to your question, yes it is consider as a seperate method

Hope this helps you


Actually technical term for that is hiding and supposedly overridden class methods are not separate methods, they just don't do what you expect. For instance method, which method to call is decided on runtime based on the object type (run time polymorphism), but in case of class method, there is no ambiguity whose method to call. Remember, how you call a static method of a class. Do you need an object of that class to call its static method? No, jvm simply looks the reference variable type to call its static method, this way child class static method is never called if ref var type is of super class (static polymorphism). Look at this explanation
s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
hi according to the program you given..
the methods you declared are called as overloaded methods and not overrided methods...
overloaded methods will have same method name but with different no of arguments or with different argument types...
overrided methods will have same method name,same no of arguments with argument types...

With Regards,
S.Palanivel Rajan B.E.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Rahul.p Kumar wrote:
Actually technical term for that is hiding and supposedly overridden class methods are not separate methods, they just don't do what you expect. For instance method, which method to call is decided on runtime based on the object type (run time polymorphism), but in case of class method, there is no ambiguity whose method to call. Remember, how you call a static method of a class. Do you need an object of that class to call its static method? No, jvm simply looks the reference variable type to call its static method, this way child class static method is never called if ref var type is of super class (static polymorphism). Look at this explanation


cant understand that what you want to tell? . see the parameter of the two methods
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
seetharaman venkatasamy wrote:Overriding methods signature[name & parameter] must be same .


I agreed and believed that kri shan got your point that, it is not a case of overriding. In case your following statement was to show how a static method override works, then I corrected that portion.

seetharaman venkatasamy wrote:if that methods are static then it is not consider as Override instead it consider as redifined .

Coming to your question, yes it is consider as a seperate method

Hope this helps you


Your answer is correct in case Kri shan didn't meant "how override works in case method is static"

Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
seetharaman venkatasamy wrote:if that methods are static then it is not consider as Override instead it consider as redifined .


Here do you mean that if methods were not static and had different signature, it was case of override. from here I took the cue that you people are talking about static override and in that case "redifined" word is incorrect.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Rahul.p Kumar wrote:
from here I took the cue that you people are talking about static override


there is nothing called static override. redefinition is different from override

For your Information http://www.coderanch.com/t/411202/Beginning-Java/java/difference-between-redefining-overriding-method
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

kri shan wrote:meth1 is not overrided method in Parent and Child classes. Whether meth1 will be considered sepate method in parent class and child class ?

When you extend a class, we do not call the extended class the "parent" class, and we do not call the new class the "child" class. The extended class is the superclass, and the new class is the subclass.

The meaning of the word "inheritance" in object oriented programming is very different from the biological meaning of the word, and therefore you should not use biological terms such as "parent" and "child" - those don't apply here and only confuse things.

In object oriented programming, inheritance indicates an is-a relationship - an instance of the subclass is an instance of the superclass. So by saying "class Child extends Parent", what you are saying is "a Child is a Parent", which is obviously false.

It's better to use class names such as for example Animal and Dog - class Dog extends Animal. A Dog is an Animal.
 
Don't get me started about those stupid light bulbs.
 
subject: Parent class -> Child class