Results 1 to 5 of 5
- 01-19-2011, 12:33 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Accessing Constructor from another Class
I need to access a constructor called "car" from a test class:
public class car {
private ArrayList<Integer> cs;
public car(ArrayList<Integer> cs) {
this.cs=cs;
}
}
I tried doing this (which didn't work):
public class testcar {
car c1 = new car();
c1.car();
}
Any ideas?
Thanks.
- 01-19-2011, 12:35 AM #2Java Code:
c1.car();
- 01-19-2011, 12:36 AM #3
I just realised you are also missing the parameter that the constructor is expecting to be passed to it.
- 01-19-2011, 04:38 AM #4
You need to pass the ArrayList to the car constructor, like,
Java Code:car c1 = new car(yourArrayList)
Use proper naming conventions for your code. Refer here: Naming Conventions.
GoldestLast edited by goldest; 01-19-2011 at 04:49 AM. Reason: Thanks Junky, Modified.
Java Is A Funny Language... Really!
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-19-2011, 04:41 AM #5
Similar Threads
-
Accessing class defined within a constructor
By kwaspl in forum New To JavaReplies: 4Last Post: 12-21-2009, 02:35 PM -
problem in accessing array values of one class in to jframe class
By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 09:34 AM -
[SOLVED] Accessing private constructor
By piyu.sha in forum New To JavaReplies: 2Last Post: 10-06-2008, 05:45 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM
Bookmarks