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 the difference between @before and @beforeclass annotation?
what are three ways in which a thread can enter the waiting state? : Java thread
What is treemap in java?
Why set do not allow duplicates in java?
What are the benefits of operations in java?
How is java hashmap implemented?
How will you compute size of a structure?
What is api data?
How many types of keywords are there?
Can a method be static?
What is the properties class?
What is the difference between array list and vector in java?
If you do not want your class to be inherited by any other class. What would you do?
What does the “static” keyword mean?
What are default methods ?