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
Explain different ways of creating a thread?
Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?
Why does java have two ways to create child threads?
What is collection api?
Explain the protected field modifier?
Write a program to print all permutations of string?
What do you mean by an object in java?
What is the ==?
What is treeset and treemap in java?
Difference between method overloading and overriding.
How a variable is stored in memory?
What is the size of integer?
What is assembly condition codes?
What is Gang of four design patterns
how come we know the object is no more used in the class?