• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Is ArrayList an AbstractClass?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could any one explain me why and how the ArrayList is an AbstractClass

I found that it implements AbstractArrayList andimplements List interface.

How to justify on this?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList is not an Abstract Class . If a class extends an abstract class, it does not mean the subclass in an Abstract.

and Welcome to JavaRanch
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hari Hara Kumar wrote:Could any one explain me why and how the ArrayList is an AbstractClass

I found that it implements AbstractArrayList andimplements List interface.

How to justify on this?



A class extending an Abstract class or implementing an interface is not Abstract provided its not declared as abstract. Sp ArrayList is not an Abstract class. Did you try creating an instance of ArrayList? Have you read about Abstract classes in Java?
 
Elayaraja David
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do exactly know the abstract class and its necessity
But, I got couple of interview questions stating ArrayList is an abstract class and please mention the methods which needs to be implemented?
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hari Hara Kumar wrote:
But, I got couple of interview questions stating ArrayList is an abstract class and please mention the methods which needs to be implemented?


Oh! Are you sure its ArrayList? I have instantiated it "n" number of times. And the API also doesnt state its abstract. Wondering about the person who asked this question.
 
author
Posts: 23958
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

Hari Hara Kumar wrote:I do exactly know the abstract class and its necessity
But, I got couple of interview questions stating ArrayList is an abstract class and please mention the methods which needs to be implemented?



One possibility is that you misunderstood the interviewer -- maybe he/she said an ArrayList IS-A AbstractList, or an ArrayList IS-A AbstractCollection.... which of course, is true because any subclass IS-A superclass (can be used where a superclass is needed).

Henry

 
Elayaraja David
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok.
I might wrongly understood the question.

List<Employee> list = new ArrayList<Employee>();

Could any one explain what happens behind the screen? I know its a silly question but i am bit confused here.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hari Hara Kumar wrote:Oh ok.
I might wrongly understood the question.

List<Employee> list = new ArrayList<Employee>();

Could any one explain what happens behind the screen? I know its a silly question but i am bit confused here.



Nothing happens behind the scenes. The Object referenced is still an Object of type ArrayList<Employee>, and list is a variable of type List<Employee>
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hari Hara Kumar wrote:I might wrongly understood the question.
Could any one explain what happens behind the screen? I know its a silly question but i am bit confused here.


The best thing is probably to look at the docs for ArrayList, because right at the top it shows you the hierarchy:
java.lang.Object → java.util.AbstractCollection → java.util.AbstractList → java.util.ArrayList

The reason for this is that each level "fills in the blanks" for certain methods, providing them with default implementations.

It should also be noted that ArrayList is NOT final, so you can extend it to create a class of your own if you want; probably pointless, but it can be done.

Winston
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

It should also be noted that ArrayList is NOT final, so you can extend it to create a class of your own if you want; probably pointless, but it can be done.

Winston


Not pointless, but it's the solution for a very specific problem that I suppose is infrequently encountered. If you have a class that needs to know when elements are added to or removed from a List, then you need a list that can be observed and which notifies listeners when these events occur. You could make your own implementation of the List interface from scratch, but simpler is to extend ArrayList and override the add/remove methods.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dennis Deems wrote:If you have a class that needs to know when elements are added to or removed from a List, then you need a list that can be observed and which notifies listeners when these events occur. You could make your own implementation of the List interface from scratch, but simpler is to extend ArrayList and override the add/remove methods.


And don't forget about addAll, set and clear. Not sure I didn't overlook yet another, though.
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic