473,385 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

method overidden problem .....

dmjpro
2,476 2GB
class A
{
void test(int a)
{
System.out.println("Normal .... Class A");
}
}

class B extends A
{
int test(int a)
{
System.out.println("Class B");
}
}
i have this code .. a comiler error comes .... here in class B the method can't be overidden ..... why this happens

i think .. it is due to method signature mismatching or anything else ... plz explain and if possible plz explain me in details method signature .......


any help is most welcome ....
Mar 17 '07 #1
10 1386
r035198x
13,262 8TB
i have this code .. a comiler error comes .... here in class B the method can't be overidden ..... why this happens

i think .. it is due to method signature mismatching or anything else ... plz explain and if possible plz explain me in details method signature .......


any help is most welcome ....
DJ, if you do get time please read the classes here.

You cannot override on return types except in 1.5 with co-variant return types. In that code you have different return types and one is not a subclass of the other so that won't work.
Mar 17 '07 #2
dmjpro
2,476 2GB
thanx for ur reply .....

but i think tell me ... what is method signature and how it is important in mothod override ....

thanxxxx
Mar 17 '07 #3
dmjpro
2,476 2GB
thanx for ur reply .....

but tell me ... what is method signature and how it is important in mothod override ....

thanxxxx
Mar 17 '07 #4
r035198x
13,262 8TB
thanx for ur reply .....

but tell me ... what is method signature and how it is important in mothod override ....

thanxxxx
signature is a combination of
method name,
method arguments,
types of arguments,
order of types of arguments
and number of arguments.

If two methods have exactly the same of these then the two methods have the same signature.

You can only override a method with one with the same signature and the same or covariant return types.
Mar 17 '07 #5
dmjpro
2,476 2GB
right now i m clear .... but plz tell me one more thing .....


subsignature ....... thanxxx
Mar 17 '07 #6
r035198x
13,262 8TB
right now i m clear .... but plz tell me one more thing .....


subsignature ....... thanxxx
From the JLS

"The signature of a method m1 is a subsignature of the signature of a method m2 if either

  • m2 has the same signature as m1, or
  • the signature of m1 is the same as the erasure of the signature of m2."
Mar 19 '07 #7
dmjpro
2,476 2GB
would u be more clear ... beacause i also saw the line but not understood .....

thanxxxx
Mar 19 '07 #8
r035198x
13,262 8TB
would u be more clear ... beacause i also saw the line but not understood .....

thanxxxx
Have you done any generics yet, DJ?
Mar 19 '07 #9
dmjpro
2,476 2GB
without doing generics can't it be understood???
Mar 19 '07 #10
r035198x
13,262 8TB
without doing generics can't it be understood???
Unfortunately.
There are not too difficult to understand
Here is a simple tutorial for them.
Mar 19 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Dave Rahardja | last post by:
OK, so I've gotten into a philosophical disagreement with my colleague at work. He is a proponent of the Template Method pattern, i.e.: class foo { public: void bar() { do_bar(); } protected:...
5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
4
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)>...
7
by: greenflame | last post by:
I am trying to make a matrix object. I have given it some properites. I am trying to add a method. When I call the method by Test.showDims(...) I want to only enter one input, that is the method by...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
10
by: Mihai Osian | last post by:
Hi everyone, Given the code below, can anyone tell me: a) Is this normal behaviour ? b) If it is, what is the reason behind it ? I would expect the A::method(int) to be inherited by B. ...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
3
by: allendowney | last post by:
Hi All. In a complex inheritance hierarchy, it is sometimes difficult to find where a method is defined. I thought it might be possible to get this info from the method object itself, but it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.