There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
So now my problems are intialising these variables:
colour --> white
sqaure_number --> 0
Maybe, public void move()
it will allways be replaced in the constructor.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
but I'm still unsure where to intialise my variables? Do i intialise in the constructor or at the top? Am I structuring my code logically?
you could create a couple more constructors... one that takes no parameters, one that takes only an int, and one that takes both. at the very least, i'd create the constructer that takes no arguments:
How can I first look at the default value? Then presumably I can change the colour using the constructor.
How can I create one that takes both?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Varargs
The varargs functionality allows multiple arguments to be passed as parameters to methods. It requires the simple ... notation for the method that accepts the argument list and is used to implement the flexible number of arguments required for printf.
void argtest(Object ... args) {
for (int i=0;i <args.length; i++) {
}
}
argtest("test", "data");
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |