• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does overriding happen during compile time

 
nadeem shake
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question related to the below code .

the question is : i think that when i create the object "Temp x = new Temp();"
and call the method using " x.met1();" it should call the method inside the subclass Test39 which is "int met1()" , i think this way because i am creating the object for that particular class which is Test39,

but it gives me an error stating

Test39.java:9: met1() in Test39 cannot override met1() in Temp; attempting to use incompatible return type
found : int
required: void
int met1()

i understand that the int should be changed to void to remove this error because i am trying to override the void met() method which is inside the
temp class, but the question still remains in my stupid mind that how does the compiler come to know there are two methods with the same name but with different return types , does it do this checking during compile time ???



sorry guys if this is a stupid question i have no one to ask to so i am asking here and i hope that i can learn java from this forum and i have joined this forum with that intention in my mind . thanks guys for the support



 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nadeem shake wrote:the question still remains in my stupid mind that how does the compiler come to know there are two methods with the same name but with different return types , does it do this checking during compile time ???

Ofcourse the compiler checks that at compile time. It analyzes your source code and sees that the met1() method in class Test39 has a different and incompatible return type (int) than the met1() method in its superclass Temp (void).
 
Winston Gutkowski
Bartender
Pie
Posts: 10257
59
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nadeem shake wrote:...and i hope that i can learn java from this forum and i have joined this forum with that intention in my mind...

My advice: Don't think that you can learn Java from this forum.

If you really are trying to learn on your own, you really should get a decent book - this one has a very good reputation - or read the Java Tutorials and follow the exercises thoroughly.

We can help with advice if you run into difficulties; but trying to learn a language as complex as Java from a forum like ours will be time-consuming and frustrating for both you and us.

Winston
 
nadeem shake
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
nadeem shake wrote:...and i hope that i can learn java from this forum and i have joined this forum with that intention in my mind...

My advice: Don't think that you can learn Java from this forum.

If you really are trying to learn on your own, you really should get a decent book - this one has a very good reputation - or read the Java Tutorials and follow the exercises thoroughly.

We can help with advice if you run into difficulties; but trying to learn a language as complex as Java from a forum like ours will be time-consuming and frustrating for both you and us.

Winston


i would like to say that i have 2 books on java , the book that you mentioned i already own , I just ask when i am not able to understand a concept from the book or if i have some doubt , i am not asking anybody to be my tutor here i just ask for small helps when i run into trouble even after reading books and all , and its not frustrating for people to help if they really want to help . thanks
 
nadeem shake
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
nadeem shake wrote:the question still remains in my stupid mind that how does the compiler come to know there are two methods with the same name but with different return types , does it do this checking during compile time ???

Ofcourse the compiler checks that at compile time. It analyzes your source code and sees that the met1() method in class Test39 has a different and incompatible return type (int) than the met1() method in its superclass Temp (void).


Thanks a lot for clearing my doubt !!! i really appreciate that
 
Winston Gutkowski
Bartender
Pie
Posts: 10257
59
Eclipse IDE Hibernate Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nadeem shake wrote:...and its not frustrating for people to help if they really want to help...

You wanna bet?

It very much depends on what your expectations are. If you're prepared to put in the time and effort to learn - and I have no reason to think you won't - and also to ask questions in a clear and precise way (have a look at the HowToAskQuestionsOnJavaRanch page, because there's a lot to know about it), I'm sure nobody will have any problems at all.

On the other hand, if you simply look on us as a service for answering whatever question comes into your head, you may get some pithy responses.

Anyway, welcome to the Ranch, and the best of luck with your studies.

Winston
 
nadeem shake
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
nadeem shake wrote:...and its not frustrating for people to help if they really want to help...

You wanna bet?

It very much depends on what your expectations are. If you're prepared to put in the time and effort to learn - and I have no reason to think you won't - and also to ask questions in a clear and precise way (have a look at the HowToAskQuestionsOnJavaRanch page, because there's a lot to know about it), I'm sure nobody will have any problems at all.

On the other hand, if you simply look on us as a service for answering whatever question comes into your head, you may get some pithy responses.

Anyway, welcome to the Ranch, and the best of luck with your studies.

Winston


it is not any whatever question that came into my head , it was a question that i was unable to get answer on my own that's why i asked here. and i dont look at this forum as a service but as a means of help and guidance nothing more and nothing less.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic