Pin It

How Aliasing affects Java's reference variable ?.

Program to demonstrate how aliasing affects Java's reference variable

class Triangle {
 
  public int width;
 
}

public class AliasingEffect {
 
  public static void triangleAlias(Triangle triangle){
  
    triangle.width = 20;
  
  }
 
  public static void main(String[] args) {
  
    Triangle triangleOne = new Triangle();
    triangleOne.width = 10;
  
    System.out.println("1: triangleOne's width = " + triangleOne.width);
  
    triangleAlias(triangleOne);
  
    System.out.println("2: triangleOne's width = " + triangleOne.width);

  }

}




Output of the program :



Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot