Question

Mention the concepts analyzed from the below given program and write the output. [0.5 M] class...

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); } }

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); }...
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); } String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; } public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); } } Select one: a. spicy b. the program does not compile c. bland spicy d. no output e. bland
What is the output of the following Java program? class Food { String flavor = "bland";...
What is the output of the following Java program? class Food { String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; Pepper(String flavor) { this.flavor = flavor; } } public class Lunch { public static void main(String[] args) { Pepper pepper = new Pepper("sweet"); System.out.println(pepper.flavor); } } Select one: a. bland b. the program does not compile c. no output d. spicy e. sweet
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
What is the output of the following Java program? interface Food {     public void printFlavor();...
What is the output of the following Java program? interface Food {     public void printFlavor(); } class Pepper implements Food {     public void printFlavor() { System.out.println("spicy"); } } public class Lunch {     public static void main(String[] args) {        Food pepper = new Pepper();         pepper.printFlavor();     } } Select one: a. spicy b. no output c. the program does not compile d. bland e. bland spicy
Write an interactive version of the InchesToFeet class that accepts the inches value from a user....
Write an interactive version of the InchesToFeet class that accepts the inches value from a user. class InchesToFeetInteractive {       public static void main(String[] args) {       // Modify the code below      final int INCHES_IN_FOOT = 12;      int inches = 86;      int feet;      int inchesLeft;      feet = inches / INCHES_IN_FOOT;      inchesLeft = inches % INCHES_IN_FOOT;      System.out.println(inches + " inches is " +         feet + " feet and " + inchesLeft + " inches");   } }
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program.");...
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program."); } } Compile this and execute this program then modify it to display I am learning how to program in Java. Change class name to Javaprogramming.java. compile and execute. Modify the Javaprogramming class so it prints two lines of output. Change name to Awesome. Add second output statement that displays That's awesome ! Save as awesome.java then compile and execute