The question is about stating the output of the program from output 1 till outpu
ID: 3703394 • Letter: T
Question
The question is about stating the output of the program from output 1 till output 8, each output number is marked on the test class
for example: //output 1, //output 2
publie class Room ( public class testRoom private int size; public static void maintStringll args) t publie statie int num -1, Room 1- new Room(20,4) System.out.printinl"ri:-+rl) System.out 1 output public Room@I this(S):) public Room(int sHsize- public Room(int a, int b)f size-a; num - b out printin-Room.numRoom.nun):foutut 2 Room r2-new Roon) System.out.printin 2:-+12):11output 3 r1.changet35): System.out.printin("ri:-+rl:f outputa public int getsizeDfreturn size ) public vold changefint xH size num** ) publie static void change(Inum System.out printin("ri:r2): / output 5 Room special - r1.same) r1.changel15) public Room same()freturn this; ) System.out.printin special:" +special), II output 6 System.outprintint.r1:"+r1); //output ? public String toStringtf return "Size--+ size +-·id-+ num; Room.change() System.out.printinl"special:"+ special); // output 8Explanation / Answer
Answer)
The given program is :
public class Room{
private int size;
public static int num = 1;
public Room(){this(5);}
public Room(int s){size=s;}
public Room(int a, int b){size=a; num = b;}
public int getSize(){return size;}
public void change(int x){size=x; num++;}
public static void change(){num++;}
public Room same(){return this;}
public String toString(){
return "size ="+size+", id="+num;
}
}
public class TestRoom {
public static void main(String[] args){
Room r1 = new Room(20,4);
System.out.println("r1: "+r1);
System.out.println("Room.num "+Room.num);
Room r2=new Room();
System.out.println("r2: "+r2);
r1.change(35);
System.out.println("r1: "+r1);
System.out.println("r1: "+r2);
Room special = r1.same();
r1.change(15);
System.out.println("special: "+special);
System.out.println("r1: "+r1);
Room.change();
special.change(0);
System.out.println("special: "+special);
}
}
The output of the program is:
r1: size =20, id=4
Room.num 4
r2: size =5, id=4
r1: size =35, id=5
r1: size =5, id=5
special: size =15, id=6
r1: size =15, id=6
special: size =0, id=8
Now let's fillup the output sheet:
Output 1: r1: size =20, id=4
Output 2: Room.num 4
Output 3: r2: size =5, id=4
Output 4: r1: size =35, id=5
Output 5: r1: size =5, id=5
Output 6: special: size =15, id=6
Output 7: r1: size =15, id=6
Output 8: special: size =0, id=8
I hope the answer helps you.
Please comment for any queries and Please Rate my answer if you Like it.
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.