Consider the following method definition that has been properly defined in the c
ID: 3679169 • Letter: C
Question
Consider the following method definition that has been properly defined in the class Time.
void shiftBy(int dh, int dm) {
hour += dh; minute += dm; }
public static void main(String[] args)
{ int x = 2; int y = 4; Time mytime = new Time(); mytime.shiftBy(x, x); }
What are the values of hour and minute after the function shiftBy finishes?
A. hour is 2, but minute is 4.
B. Both hour and minute are 2.
C. hour is 0, but minute is 2.
D. Both hour and minute are 0.
——————————————————————————————————————————————————————
Consider the following class definition.
class myclass {
int addition (int a, int b) //method overloading
{ int r; r= a + b; return r; }
void addition (int a, int b, int c)
{ System.out.print("Total is now: "); System.out.println(a + b + c); } }
Another method is created in the same class with the local integer variables x, y and z. Which of the following statements would produce an error if you included it after variables a and b are defined and initialized to 1?
A. addition(x, y, z);
B. addition(y, x);
C. addition(x, y);
D. addition(x);
———————————————————————————————————————————————————————
Consider the following class definition: class world { public void greetings() { System.out.println("Hola"); } } Which statement(s) would you use to add a class variable named myinteger?
A. private myinteger;
B. private integer myinteger();
C. private int myinteger;
D. integer myinteger;
Explanation / Answer
void shiftBy(int dh, int dm) {
hour += dh;
minute += dm; }
public static void main(String[] args)
{ int x = 2; int y = 4;
Time mytime = new Time();
mytime.shiftBy(x, x); }
What are the values of hour and minute after the function shiftBy finishes?
The values of hour and minute, depends on their initial values, which were initialized in the constructor Time().
Assuming, both the variables are initialized to 0, the above code will shift the values using the line mytime.shiftBy(2,2).
Therefore, after executing the function, hours value and minutes value both will be 2.
So, answer is B. Both hour and minute are 2.
class myclass {
int addition (int a, int b) //method overloading
{ int r;
r= a + b;
return r; }
void addition (int a, int b, int c)
{ System.out.print("Total is now: ");
System.out.println(a + b + c); } }
Another method is created in the same class with the local integer variables x, y and z. Which of the following statements would produce an error if you included it after variables a and b are defined and initialized to 1?
D. addition(x); this will lead to an error, as you defined only 2 functions, one with 2 parameters, and the other one with 3 parameters. And this function call, will not find any suitable prototype.
class world {
public void greetings()
{ System.out.println("Hola"); }
}
Which statement(s) would you use to add a class variable named myinteger?
C. private int myinteger will add an integer variable myinteger to the class, as a private member.