• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Extending Arrays class

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrays class in util package is marked public.....

But when i tried to extend it .....a following error is thrown by my Compiler...

Arrays() has private access in java.util.Arrays


Thanks !!!
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrays is a utility class with only static methods which obviously can't be overridden. Why would you want to extend it?
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sahil Kapoor wrote:Arrays class in util package is marked public.....

But when i tried to extend it .....a following error is thrown by my Compiler...
Arrays() has private access in java.util.Arrays
Thanks !!!



Arrays has private Constructor?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:
Arrays has private Constructor?



Which can be quickly confirmed by taking a look at the source...

http://www.docjar.com/html/api/java/util/Arrays.java.html

Henry
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO private constructor has nothing to take with subclassing.

Arrays is marked public so it should be subclassed even if all its members are static. I have an idea that static members cannot be overriden but can be redefined.

But my question is ....Arrays is marked public and still cannot be subclassed ??? Why ??
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sahil Kapoor wrote:IMO private constructor has nothing to take with subclassing.



Of course the constructor affects subclassing. Remember that the constructor has to call the super classes' constructor via a call to super(). Even if no such call is made, a call to the default no-arg constructor is inserted. If the subclass doesn't have permission to access the super constructor, then it can't construct the super portion of the object ... hence, compile error.

Sahil Kapoor wrote:
But my question is ....Arrays is marked public and still cannot be subclassed ??? Why ??



The Arrays class *can* be subclassed ... but only from classes that can access the Array constructors. And since they are private, this is limited to the Arrays classes' inner classes.

Henry
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry for that link....
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry Wong and Abimaran Kugathasan !!!

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the credits to Henry..... Thanks......
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic