Question

In: Computer Science

When are values passed as parameters? a. When parameters are primitives or wrappers b. When parameters...

When are values passed as parameters?

a. When parameters are primitives or wrappers

b. When parameters are user-defined objects

c. When parameters are objects

What is the result of a == b?

public static void main(String[] args) {

int[] a = {1, 2, 3};

int[] b = {1, 2, 3};

}

a. True

b. False

c. Compile Error

Solutions

Expert Solution

I have explained all the three parameters along with examples in order to make it clear.

Second question , answer is false .

I have provided reasoning .

If you have nay problem, feel free to ask.


Explanation:

Ans (a)

When parameters are primitive , then we can pass values with primitive data types like (int , short int , long , double , float , char , boolean, byte )

For eg:

int Sum( int a , int b)

return a+b;

Here a and b are primitive parameters

Ans (b)

When parameters are user defined objects , they are passed using constructor function.

For eg:

Class sum()

{

int sum( int a , int b)

{

this.a = 5;

this.b = 7;

return a+b;

}

Here a and b are user defined objects.

Ans (c)

Objects as parameters can also be passed in java , in any function.

For eg:

Class student {

import java.util.Scanner;

public class Student {

  private String name;

  private int age;

  public Student(){

  }

  public Student(String name, int age){

   this.name = name;

   this.age = age;

  }

  public Student copyObject(Student std){

   this.name = std.name;

   this.age = std.age;

   return std;

  }

  public void displayData(){

   System.out.println("Name : "+this.name);

   System.out.println("Age : "+this.age);

  }

Here copyobject() function takes objects of student class (std) as parameter.( I have boldened it to highlight)

Q- Result of a==b

(b) False

The result is false because these two arrays are reference to two different objects and when we use comparison operator(==), it compares reference variables. Therefore the result is false .

But if we want to compare two arrays in java, a method called Arrays . equals() is provided . We may pass arrays as parameters , in order to compare.


Related Solutions

Make a function that swaps the values that change the values between the parameters as the...
Make a function that swaps the values that change the values between the parameters as the following rule. The functions swap takes 2, 3 or 4 parameters and these functions are implemented as the overloading functions. swap(int &, int &) : change the values each other. swap(int &, int &, int &) : change the value with the order. [min, medium, max] swap(int &, int &, int &, int &) : change the value like circular-shift-right [A, B, C, D]...
you will be analyzing the cumulative summing, the different number of parameters that can be passed...
you will be analyzing the cumulative summing, the different number of parameters that can be passed to a method, and the design methods with no parameters. Instructions: Answer the following questions:1. Describe how you create and use a method with multiple parameters. 2. Explain what happens when you call a method and the method ends. 3. Discuss the cumulative summing relationship. 4. List the four things you need to know when you call a method from a program or other...
For C++ Make a function that swaps the values that change the values between the parameters...
For C++ Make a function that swaps the values that change the values between the parameters as the following rule. The functions swap takes 2, 3 or 4 parameters and these functions are implemented as the overloading functions. swap(int &, int &) : change the values each other. swap(int &, int &, int &) : change the value with the order. [min, medium, max] swap(int &, int &, int &, int &) : change the value like circular-shift-right [A, B,...
Write a method that concatenates two strings passed as parameters.    Version #1 - assign to...
Write a method that concatenates two strings passed as parameters.    Version #1 - assign to the 1st parameter the concatenation of both parameters. Perform the concatenation using the + operator. We are assuming reference parameter work that way (they don't).    Version #2 - fine. return the value of the 1st param after concatenating to it the second parameter then.    Version #3 - Let's do it the proper way now, I say. Create a temporary String reference variable...
In C++ Having call-by-reference allows one to use storeback parameters, i.e., parameters whose values are transmitted...
In C++ Having call-by-reference allows one to use storeback parameters, i.e., parameters whose values are transmitted back to their arguments. In this exercise, you are to write a program that provides several variations of a function that calculates the minimum of two values. Several of the functions also report whether the two values passed in were equal. The functions are all named min — they differ in their arguments and return values: Accept two integers and return their minimum Accept...
Hypothesis testing is a statistical procedure for assessing claims about parameters or statistics? a. parameters b....
Hypothesis testing is a statistical procedure for assessing claims about parameters or statistics? a. parameters b. statistics QUESTION 2 A claim made about a parameter is called the _____ hypothesis. a. alternative b. null QUESTION 3 The statement that you want to find statistical evidence for is the _____ hypothesis. a. alternative b. null QUESTION 4 If statistical evidence is found against the null hypothesis, then we _____ the null hypothesis. a. fail to reject b. reject QUESTION 5 Suppose...
What are returns to scale? Under what conditions (that is, for what values of the parameters...
What are returns to scale? Under what conditions (that is, for what values of the parameters a and b) does the Cobb-Douglas production function,q = KaLb, exhibit constant and increasing returns to scale? (Hint: See Solved Problem 6.3.)
Using the currently accepted values of the cosmological parameters, and assuming the validity of the CDM...
Using the currently accepted values of the cosmological parameters, and assuming the validity of the CDM Model (what Ryden calls the Benchmark Model), (a) determine the total baryonic mass in the observable universe (that is, within the particle horizon). Express your answer in solar masses, and also in number of baryons, and finally in joules. (b) Do the same for the total amount of dark matter, expressed in solar masses. (c) Calculate the total energy of CMB photons in the...
1. What considerations are important when choosing experimental parameters? 2. What are the kinetic parameters of...
1. What considerations are important when choosing experimental parameters? 2. What are the kinetic parameters of a heterogeneous reaction?
What is HIPAA? A. When was it passed? What led to it? What are the key...
What is HIPAA? A. When was it passed? What led to it? What are the key provisions of it? How does it relate to Medicare/Medicaid?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT