Computer Science, asked by isaiahmurillomasterb, 7 months ago

The value stored by a variable can be changed after it is assigned.

Answers

Answered by namrutha0209
0

Answer:

How can I make sure that the value of String variable doesnot change after being assigned once? Assignment is not at the time of declaration.

More clarity :-

String x = y; (y is another string) Even if y changes x should not change. How to make sure this?

What I have tried :-

Created a custom class:-

public class MyDs {

   private final String unitName;

   public MyDs(String iUnitName){

       unitName   =   iUnitName;

}

   public String getUnitName(){

       return unitName;

   }

}

in the main method :-

String iName = "xyz";

MyDs MyDsObj  = new MyDs(iName);

But even after this, the value changes when the variable changes

THANK YOU AND PLEASE MARK ME AS BRAINLIEST

Similar questions