File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Any One Explain Me The Following Codes Briefly

 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator








Code1: No Compile Error
Code2: Compile Error
Code3: Compile Error



[ October 09, 2008: Message edited by: Thangaraj Raj ]
[ October 09, 2008: Message edited by: Thangaraj Raj ]
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Thangaraj this is a unique kind of a problem. This is why you had to wait for two days. And this is also not a perfect solution that I am providing. I compiled your codes and it gives this error message

name clash: <T>say() in Child and say() in Parent have the same erasure, yet neither overrides the other.

In both the second and the third code, the error is similar. Somehow the compiler is not able to deduce that the say method in Child class is overriding the say method in Parent class. So it says that they have the same name but say in child doesn't override say in Parent.

I also tried to add an @Override annotation, but that too gives an error that no method is being overriden. the 2nd example is especially shocking. You have just added a <T> and haven't even used it anywhere. But still the compiler gives a warning.

I read through Generics FAQ by Angelika Langer, and it says on page 466

a class (subclass in this case) must not have methods with identical erasures


The FAQ also states that a non-generic method can override a generic method but not vice versa, as is happening in your case.

So basically you have to memorize it for now. If I get a reason for this behavior, I will definitely help you.

If anyone has any idea, please comment...
 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much...
Actually I am preparing For scjp just finished reading the kathy sierra bert bates...
now next what i want to do...
what type of mock exam i want to take.. can you give some valuable sites for mock test.
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the thumb rule for overriding is that the overriden method cannot have more visibility than its parent method.

The generic overloaded meethod is trying to do the same thing.
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the thumb rule for overriding is that the overriden method cannot have more visibility than its parent method.

The generic overloaded meethod is trying to do the same thing.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Harshit Rastogi:
the thumb rule for overriding is that the overriden method cannot have more visibility than its parent method.
I am afraid you have got that the wrong way round; the overridden method cannot have less "visibility" than its superclass counterpart.

If the superclass method is public, then it can only be overridden as public; if it is default or protected it cannot be overridden as private.
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Harshit I agree with Campbell. Also I don't know how it is applicable here as all the methods have default(package) visibility.

@Thangaraj you can view a list of good free and paid mock exams in the javaranch SCJP mock exams list
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic