Mention the concepts analyzed from the below given program and write the output. [0.5 M]
class Test {
int a, b;
Test(int i, int j)
{ a = i; b = j;
}
void meth(Test s)
{ s.a *= 2; s.b /= 2; }
}
class demo {
public static void main(String args[]) {
Test ob = new Test(15, 20);
System.out.println("Before call: " + ob.a + " " + ob.b);
ob.meth(ob);
System.out.println("After call: " + ob.a + " " + ob.b); } }
Output:
Before call: 15 20
After call: 30 10
here we are creating the object using the parameterized constructor with values 15 20 so now ob will have values as 15 20 in it
next we are calling meth using the ob object and also passing the same object as parameter in meth
we multiplying a * 2 and dividing b with 2 so it will become 30,10 in the ob object which we passed
so when we are printing in main() it will print 30 10
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Get Answers For Free
Most questions answered within 1 hours.