Answer Posted / java
1.Make the class as final
2.Make the data members as private
3.write the public getter methods
Ex:
public class ClassImmutable {
public static void main(String[] args) {
ImmutableTest it=new ImmutableTest(10,"Count");
System.out.println(it.getString());
System.out.println(it.getValue());
}
}
final class ImmutableTest{
private int i;
private String str;
public ImmutableTest(int i,String str){
this.i=i;
this.str=str;
}
public int getValue(){
return i;
}
public String getString(){
return str;
}
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Is java ee a framework?
How will you initialize an Applet?
What's the base class in java from which all classes are derived?
Is binary a low level language?
What are the steps involved to create a bean?
Write a program to search a number in the given list of numbers.
What is a final class ?
What are the basic interfaces of java collections framework?
what do you mean by java annotations?
Q1.A. Write note on “The class path Environment Variable”? B. Which are different kinds of source code? Q2.A. How to create an interface? B. Why convert an applet to an application? Q3.A. How to use Media tracker Class. B. How to use string tokenizer class. Q4 A. Explain the overview of UDP messaging. B. Difference between SQL Exception class and SQL Warning class. Q5. A. How to create com object in Java? B. Write short notes on “The properties class” Q6. A. When object is created and destroyed? B. Explain the JDB in depth & command line. C. Write short notes on Web Sites.
What is the difference between overriding and overloading in OOPS.
What is binary tree in java?
What is definition and declaration?
What do heavy weight components mean in java programming?
What does localhost mean?