wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes does overriding happen during compile time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "does overriding happen during compile time " Watch "does overriding happen during compile time " New topic
Author

does overriding happen during compile time

nadeem shake
Greenhorn

Joined: May 01, 2013
Posts: 9
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7529
    
  18

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
nadeem shake
Greenhorn

Joined: May 01, 2013
Posts: 9
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

Joined: May 01, 2013
Posts: 9
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

Joined: Mar 17, 2011
Posts: 7529
    
  18

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

Joined: May 01, 2013
Posts: 9
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.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: does overriding happen during compile time
 
Similar Threads
Are my answers correct ?
clarification regarding one of the rules of overriding given in scjp 6 study guide by Kathy and Bert
Change icon color dinamically
Specific match rule
multi-level inheritance problem