• Breaking News

    Copy Constructor ব্যবহার করে জাভা প্রোগ্রাম



    প্রোগ্রামের সোর্স কোড-


    public class Number
    {
        public int x;
        public int y;
      
        //Constructor
        public Number(int x, int y)
        {
            super();
            this.x = x;
            this.y = y;
        }
      
        //Copy Constructor
        public Number(Number p)
        {
            this.x = p.x;
            this.y = p.y;
        }
      
        public static void main(String[] args)
        {
            Number p1 = new Number(5,6);
          
            Number p2 =  new Number(p1);
          
            System.out.println(p1.x + " " + p1.y);
            System.out.println(p2.x + " " + p2.y);
          
            p2.x = 7;
            p2.y = 8;

            System.out.println(p1.x + " " + p1.y);
            System.out.println(p2.x + " " + p2.y);
        }
    }
     
    প্রোগ্রামটি রান করলে যে আউটপুট পাবো তা হলো:
    $javac Number.java
    $java -Xmx128M -Xms16M Number
    5 6
    5 6
    5 6
    7 8

    পরবর্তী প্রোগ্রাম- 

    No comments