Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. To use a predefined method you must know the code in the body of the method.

ID: 3712546 • Letter: 1

Question

1. To use a predefined method you must know the code in the body of the method.

a) TRUE

b)FALSE

2. The value returned by a value-returning method can be saved for further calculation in the program.

True

False

3.

A formal parameter is a variable declared in the method heading (ie. it's signature).

True

False

4.

A local identifier is an identifier that is declared within a method or block and that is visible only within that method or block.

True

False

5.

No two methods in the same class can have the same name.

True

False

6.

Void methods have no return type.

True

False

7.

The return statement must be the last line of the method.

True

False

8.

When a program executes, the first statement to execute is always the first statement in the main method.

True

False

9.

Given the method heading

public static String exampleMethod(int n, char ch)

what is the return type of the value returned?

int

char

String

Nothing will be returned

10.

The method toString() is used to convert an object to a String object.

True

False

11.

Consider the following method.

public static int minimum(int x, int y)

{

     int smaller;

     if (x < y)

          smaller = x;

     else

          smaller = y;

     return smaller;

}

Which of the following is a valid java statement which calls this method?

minimum(5, 4);

minimum(int 5, int 4);

minimum(int x, int y);

public static int minimum(5, 4);

12.

Consider the following method.

public static int minimum(int x, int y)

{

     int smaller;

     if (x < y)

          smaller = x;

     else

          smaller = y;

     return smaller;

}

What is the value of s after the following statement executes?

int s = minimum(5, minimum(3, 7));

3

5

7

None of these

13.

Given the method heading

int larger(int x, int y)

which of the following does NOT demonstrate method overloading?

int larger(int x, int y, int z)

int larger(char x)

int max(int x, int y)

double larger(double x, double y)

14.

How many constructors can a class have?

0

1

2

Any number

15.

Which of the following is NOT an actual parameter?

Expressions used in a method call

Variables used in a method call

Variables defined in a method heading

Constant values used in a method call

int

char

String

Nothing will be returned

10.

The method toString() is used to convert an object to a String object.

True

False

11.

Consider the following method.

public static int minimum(int x, int y)

{

     int smaller;

     if (x < y)

          smaller = x;

     else

          smaller = y;

     return smaller;

}

Which of the following is a valid java statement which calls this method?

minimum(5, 4);

minimum(int 5, int 4);

minimum(int x, int y);

public static int minimum(5, 4);

12.

Consider the following method.

public static int minimum(int x, int y)

{

     int smaller;

     if (x < y)

          smaller = x;

     else

          smaller = y;

     return smaller;

}

What is the value of s after the following statement executes?

int s = minimum(5, minimum(3, 7));

3

5

7

None of these

13.

Given the method heading

int larger(int x, int y)

which of the following does NOT demonstrate method overloading?

int larger(int x, int y, int z)

int larger(char x)

int max(int x, int y)

double larger(double x, double y)

14.

How many constructors can a class have?

0

1

2

Any number

15.

Which of the following is NOT an actual parameter?

Expressions used in a method call

Variables used in a method call

Variables defined in a method heading

Constant values used in a method call

Explanation / Answer

1)False. For using pre-defined methods you should now its return type and it's functionality.

2) True- Yes ,value can be stored in a variable which is same of return type of the method.

3) True-Formal parameter are those which are written in same line as that of method.example- void function(int type) here type is a formal parameter.

4) True -All local identifier/variable declared inside the function/method remains local to method onli .Can;t be used outside the method.

5) False - Two methods can have same name.It is called poymorphism basically has two types Overloading and overriding.

6) True -Void methods don't return anything.Theri is no return statment at end of void function.

7) True- Return statment must be put when function has computed all the calculation or performed all its functionalities.So,return is put at last line of any function.

8)True -All the programs start from main method.Control is given to the main method first.As language runs line by line.So,first line after main will be executed first.

9) String -Method return string data-type.Return type of any function is written before the name of the function.

10) True, toString() method in java is used to convert nay object into it's string representations.

11) minimum(5,4) -It is the basic rule/convention whih is followed to call a method from outside the function.

12) Value of s will be 3. Function minimum() will return 3 for minimum(3,7) and then minimum(5,3) will return 3 and will be stored in s.

13)double larger(double x, double y) -As for method overloading ,both methods needs to have same return types.

14) Any number. There is no restriction in having construtor in a class.

15)Variables defined in a method heading -They are called the functional paramter.