adplus-dvertising
frame-decoration

Question

What is the output of the below Java program that passes an object to another method?
class Food
{
  int items;
  int show()
  {return items;}
}

class Testing9
{
  public static void main(String[] args)
  {
    Food f = new Food();
    f.items = 5;
    System.out.println("Items Before = " + f.show());
    change(f);
    System.out.println("Items After = " + f.show());
  }
  static void change(Food foo)
  { foo.items = 10; }
}

a.

Items Before = 10
Items After = 10

b.

Items Before = 5
Items After = 5

c.

Items Before = 5
Items After = 10

d.

Items Before = 10
Items After = 5

Posted under Java Programming

Answer: (c).Items Before = 5
Items After = 10

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the below Java program that passes an object to another method?

Similar Questions

Discover Related MCQs

Q. Java object assignment happens by ___.

Q. Java object passing from one method to another method happens by ___.

Q. In Java Pass by reference ___ is passed even if you are passing a reference to an object.

Q. A Java reference is comparable to ___ in C language.

Q. ___ is the superclass to all Java classes either user-defined or built-in.

Q. State TRUE of FALSE.
Java objects have built-in methods to handle threads.

Q. State TRUE or FALSE.
Java Object's hashcode() method is mainly used with Collection objects.

Q. A Java method is comparable to a __ in c language.

Q. All Java methods must have a return type. (TRUE / FALSE)

Q. State TRUE or FALSE.
A Java method can have the same name as the class name.

Q. in Java, add a ___ to a constructor to convert it into a method.

Q. Java method signature is a combination of ___.

Q. In Java, a method name can not start with a ___.

Q. In Java, a method name can start with ___.

Q. In Java, a method name can contain numbers from 2nd character onwards. (TRUE / FALSE).

Q. Choose the correct identifier for a method name in Java.

Q. A "this" operator used inside a Java method refers to ___ variable.

Q. A local variable declared inside a method can not be used in expressions without initializing it first. (TRUE / FALSE).

Q. In Java, local variables are stored in __ memory and instance variables are stored in ___ memory.

Q. A static-method or a static-variable is shared among all instances of a class. (TRUE / FALSE)