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
Why there are some null interface in java? What does it mean?
What is the constructor?
What is meant by call by reference?
What is sizeof in java?
What do you mean by data type?
What is a blocking method in Java?
What are singleton services?
What is a java list?
What is meant by method?
Can you inherit from an abstract class java?
What is the purpose of declaring a variable as final?
What is increment in java?
Can we override private methods?
What is collection class in java?
How can u increase the heap size in the memory?