We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi, is that an interface can have a field ? I've made this but I've get an error "[...] not have been initialized"
interface theInterface {
String name;
String getName();
}
class ClassOne implements theInterface {
ClassOne(String n) {
name = n;
}
public String getName() {
return name;
}
}
/////////////////////////////////
ClassOne instance0, instance1;
void setup() {
instance0 = new ClassOne("WhatAStrangeName");
instance1 = new ClassOne("flowers");
print(instance0.getName());
exit();
}
thanks
Answers
Field variables in Interfaces are both final & static by definition! 8-X
So we gotta give them an immutable constant value, unfortunately! (~~)
Otherwise, you can use abstract classes, too.
thanks,
I've made this, using interface & Superclass. can it be easier with abstract classes ?
My take on it w/ abstract class in place of an interface: <):)