Hi, I'm a beginner programmer so apologies if this seems like a stupid question!
I've tried to initialize my field numbers with an array of numbers in a constructor in one class and then call it in my test class and display it as a string but it keeps returning null....any help would be appreciated!
This is my class that has the constructor
and this is the class that tests itCode:public class NumerbList implements Number { ArrayList<Number> numbers = new ArrayList<Number>(); //constructor taking array of type double as parameter public NumberList(Double[] numberlist){ for(int i=0; i<numberlist.length; i++){ NumberDouble numberd = new NumberDouble(numberlist[i]); numbers.add(numberd); } }
Code:public class Test { public static void main(String[]args){ Double[] d = {2.4, 3.6, 4.3, 5.1}; NumberList numbers = new NumberList(d); numbers.neg(); System.out.print(numbers.asString()); } }


Reply With Quote
