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
-
1
-
-
-
-
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).
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
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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
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
-
2
-
-
-
-
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
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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.

Consider Paul's rocket mass heater. |