This is one of the common question to be asked in interview to judge your basic level of knowledge. We all know that String is immutable which means that once object created cannot be modified or if try to modify, it will create another String literal in the String pool. So this proves that String is immutable, but this is we are proving theoretically. Now if interviewer ask you to prove the same by writing programs then you will be doing like this,

class A{

  public static void main(String[] args){

     String s="java";  // Create a object in String pool.

     s = s + "java" ; // Create another object with "javajava" as 
                         String literal in the String pool

  }

Related Posts:

  • super keyword in Java Like this in java one more most important keyword is there i.e super. super in Java has a wide use and it is mainly used to call the super class constructor explicitly by the user and implicitly used by the JVM to initialize… Read More
  • Constructor in Java Constructor is the member of the class and it has name same as class name. Constructor is the one of the important concept in java which is responsible to initialize the instance member of the class. Its functionality is lik… Read More
  • ' this ' keyword in Java this is one of the most important keyword in java which refers to the current class object. Like we are creating an object for our class similarly internally a object is there called as this which points to the current class… Read More
  • Type of inheritance in Java According to OOPS ( Object-oriented concept ) inheritance are classified into 6 category in which java support 5 of them and one is not supported in java i.e multiple inheritance for which there is a concept of interface . I… Read More
  • Inner Class in Java Inner class in a class defined as a class inside another class. So it is itself a class but first it will act as a member of that class. As we know that we cannot make a class as static but inner class can be made as static… Read More

1 comment:

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic