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

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...
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.)
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?
What is the Stark Law? When was it passed? What led to it? What are the...
What is the Stark Law? When was it passed? What led to it? What are the key provisions of it? How does it relate to Medicare/Medicaid?
A. What is the CARES Act, when was it passed, and what body was responsible for...
A. What is the CARES Act, when was it passed, and what body was responsible for passing it? B. Research one fiscal policy action included in the CARES Act. First, explain which curve(s) is/are expected to shift in the short run as a result of this action and why? Second, do you expect the action to have any effect on the long-run growth prospects of the economy? (Limit your answer to ~100 words)
Dynamic scope is an alternative to passing parameters or mutating global variables. The values of local...
Dynamic scope is an alternative to passing parameters or mutating global variables. The values of local variables can be “passed” from function to function through dynamically embedded scopes. For the following lines of Lisp, state your guess for the output before running it, and then run it. Explain what you see by drawing a call stack trace: (defvar *x* 0) (defun main () (foo) (print *x*)) (defun foo () (let ((*x* 1)) (bar) (print *x*))) (defun bar () (incf *x*)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT