Answer Posted / venu gopala reddy
a better approach. Make the immutable class itself final. Hence cannot make any sub classes, so no question of over ridding.
write code for user immutable class:-
final class ImmutableVenu{
private final int count;
private String phno="9742108000";
public ImmutableVenu(int paramCount,String paramPhno){
count=paramCount;
phno=paramPhno;
}
public int getCount(){
return count;
}
public String getString(){
return paramPhno;
}
}
public static void main(String ar[])
{
ImmutableVenu immu=new ImmutabeVenu();
s.o.p(immu.getCount());
s.o.p(immu.getPhno());
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is boolean law?
What is a nullable field?
What is nextline method in java?
What are serialization and deserialization?
explain autoboxing in java?
what is the swingutilities.invokelater(runnable) method for? : Java thread
What is difference between static and abstract class?
Explain different forms of polymorphism?
What is the difference between declaration and definition in java?
Why should I use abstract class?
What is the purpose of garbage collection in java, and when is it used?
What is empty string literal in java?
What is set string?
What is the concept of multithreading?
What is bubble sorting in java?