accessing arraylist from another class

i have an arraylist in an abstract class. I want to accesses it from another class which is not abstract.like i want to add a value from class x into the arraylist in abstract class ythnx
[208 byte] By [cyrus666a] at [2007-11-27 0:00:12]
# 1
since you can't instantiate an abstract class, this ArrayList in that class won't ever actually exist. is this other concrete class a subclass of the abstract one? have a "getList" method on the abstract class that returns it
georgemca at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 2

im creating a file storing system

i have an abstract class called vehicle

then i have 2 more abstract classes called bike and car which extends to vehicle.

then i have another 2 normal classes expensive and cheap which extends to car

what im trying to do is input car details into this system, so i can add, print out all cars etc.....so i need to create arraylists

simple data will be stored such as make, model etc

this is a similar example to what i am doing

thnx for the help

cyrus666a at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 3
I think protected would do the trick, don't quote me though.
Vagabona at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 4

sounds like a hideous design, if you ask me. why are "expensive" and "cheap" classes? they're attributes of something, not objects in their own right. how would you model a cheap bike? why are car and bike abstract? I can't understand why you think "make" and "model" are attributes of a car, but Expensive deserves to be a class of its own. and how did you decide what to make abstract and what to make concrete? why does Vehicle have this ArrayList? I think you need to re-think what you're doing. it makes no sense

georgemca at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 5

lol ok that was just an example remember.

this is the rea thing.....abstract class student

2 abstract class undergrad and postgrad extending to student

2 normal classes hons and foundation extending to undergrad

its the same as the example i gave u b4 but i dunno if this makes things better.

attributes i will need to store for the students will be name, rollnumber, course and module marks.

i need to put all this in the classes such as an arraylist so that i will be able to retrieve, add and print it all out

dont ask me y these classes been made abstract, its just the way it has to be done?

thnx

cyrus666a at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 6

> lol ok that was just an example remember.

>

> this is the rea thing.....abstract class student

>

> 2 abstract class undergrad and postgrad extending to

> student

>

> 2 normal classes hons and foundation extending to

> undergrad

>

> its the same as the example i gave u b4 but i dunno

> if this makes things better.

> attributes i will need to store for the students will

> be name, rollnumber, course and module marks.

>

> i need to put all this in the classes such as an

> arraylist so that i will be able to retrieve, add and

> print it all out

>

> dont ask me y these classes been made abstract, its

> just the way it has to be done?

says who?

you don't need - or even want - to use an arraylist to store those values. just have them as properties of the class. I wouldn't bother using all that tiresome inheritance, either. is this homework?

georgemca at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 7
lol yes its homework all about inheritance such as super classes and stuffim just really stuck on this and stresssing me out....i just need a starting point....the 1st task is just to print out all data(student details)
cyrus666a at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 8

heh heh as a rule the forum doesn't do homework, but you at least look like you've done some thinking yourself first.

since it's all about inheritance, consider the following question. you have an opportunity to impress your teacher here

I have a first class honours degree in pure mathematics. I am currently studying as an undergraduate for a degree in petro-chemical engineering. how would you represent me, using the class inheritance as you outlined above?

georgemca at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 9

oops i didnt know but i realy need help

well for me in the student class i will create fields for ur name, roll number, course?

but in the undergrad i dunno what to put in here since i will be inheriting these from student class and for hons, i will be able to inherit from student also i think?

i was thinking putting an arraylist in undergrad so i can store all these data? or would this be better in student?

also was thinking about populating the data...it seems sensible to do this at the start but i dunno where since abstract classes dont have constructors.....unless i have 2 populates one for hons and other for foundation

cyrus666a at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...
# 10
help me out peeps lol
cyrus666a at 2007-7-11 15:49:57 > top of Java-index,Java Essentials,New To Java...