aspose file tools*
The moose likes Java in General and the fly likes core java programming doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "core java programming doubts" Watch "core java programming doubts" New topic
Author

core java programming doubts

p hasini
Ranch Hand

Joined: Oct 24, 2009
Posts: 92
Please clarify some doubts:

1. When I execute this class




I get the output : In add in class A
In add in class A

Please explain what is happening here.Is it overloading or overriding.


2.I have an ArrayList



Can I make the list readonly ,no other values must be added to the List.

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Please use code tags, without code tags it is difficult to read the program.


Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Is it overloading or overriding


Because overloaded methods must differ in the type and/or number of their parameters. Therefore it is method overloading.
p hasini
Ranch Hand

Joined: Oct 24, 2009
Posts: 92
How do I set the code tags
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Can I make the list readonly ,no other values must be added to the List.

The Collections class has some utility methods to wrap collections and make them unmodifiable. For example, Collections#unmodifiableList.


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

p hasini wrote:How do I set the code tags

UseCodeTags
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

This time someone (bartender) set it for you. But please use code tags in future. using code button before posting your post, or click on edit button after posting your post and set them
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

1. The add() method in class B does not override the add() method in class A, because the argument types are not the same. X and Y are subclasses of E and S, but they are not the same. Because of this, the method to call is determined at compile time, by looking at the type of the variable a, which is A (there is no dynamic dispatch, as you would have when there was overriding).

2. You can effectively make the ArrayList read-only by wrapping it like this:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
p hasini
Ranch Hand

Joined: Oct 24, 2009
Posts: 92
Thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36501
    
  16
When it says unmodifiableList, that means the List returned cannot be modified, but it remains a copy of the original List. Any changes to the original List are reflected in the unmodifiable copy, so I think it might have been better to call the method readOnlyList.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: core java programming doubts
 
Similar Threads
Generics - need help
Generics
generics code mixed with legacy collection
Highlighting Text in JTextPane is SUPER SLOW!!
methods with parameters