final variable (variables), they are of type static or instance, must be initialized explicitly. final instance variables can also be initialized by every constructor.Three choices to make the code right:
public class Test{
static int sn;
int n;
final static int fsn; //wrong
final int fn; //wrong
}
public class Test{
static int sn;
int n;
final static int fsn = 3;
final int fn = 6;
}
public class Test{
static int sn;
int n;
final static int fsn;
final int fn;
static {fsn=6;}
{fn =8;}
}
public class Test{
static int sn;
int n;
final static int fsn;
final int fn;
static {fsn=6;}
Test(){
fn =8;
}
Test(int pn){
fn =pn;
}
}
A subclass cannot override methods that are declared final in the superclass (by definition, final methods cannot be overridden). If you attempt to override a final method, the compiler displays an error message similar to the following and refuses to compile the program:"
a subclass cannot override methods that are declared static in the superclass. In other words, a subclass cannot override a class method.
transient and static variables are not serializable.
we can use transient and static to modify the same variable.
The default constructor implicitly generated by Java compiler should have the same accessibility as the class. i.e. public class will have a public default constructor
Thursday, June 21, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment