Skip to main content

Posts

Showing posts with the label objects

Java is always Pass-By-Value. Never Pass-by-Reference. Explanation.

We often read about how Java is pass by value but very often there is a confusion that behavior is different in case of primitives and object references leading to following statement (which is kind of 'aid to memory' rather than anything else): Java does pass-by-value for primitives and pass-by-reference for object references. Consider following code snippet. public class House{   String type;   public  House (String type){     this. type =  type ;   }      public String get HouseT ype (){    return this. type ;    }      public void set HouseT ype (String  type ){    this. type =  type ;   } } public class MainClass{   public static void main(String[] args){     House myHouse; ///Line 0     myHouse = new House("Flat"); ///Line 1     System.out.println("Output1: "+myH...