Java Exercises With Solutions

Java Exercises With Solutions

Create a class named mango whose data members are a,b, and c of type integer. Create two objects. A value_set() function is only used to set the values of a,b, and c for the first object as 8, 16, and 32 respectively. Use the assignment operator to assign the first object to the second object. Define the display() function to display all the variables of two objects. Write down the output of the program as well.



class mango{
    int a,b,c;
    
    void value_set(int x1, int y2, int z3){
        a=x1;
        b=y2;
        c=z3;
    }
    void display(){
         System.out.println(a+b+c);
    }
    
}
public class javaus {
     public static void main(String[] args) {
        mango obj1=new mango(); 
        mango obj2=new mango(); 
        obj1.value_set(8, 16, 32);
        obj2=obj1;
        obj1.display();
        obj2.display();
        
     }
    
}


8 16  32
8 16  32