Given the following heading of a method, answer questions: public int DetermineR
ID: 667652 • Letter: G
Question
Given the following heading of a method, answer questions:
public int DetermineResult (int value1, char value2, String value3)
1) What is the signature of above method?
2) Which of the following is a valid overloaded method for above DetermineResult() method?
a.public double DetermineResult (int value1, char value2, String value3)
b.public int DecideResult (int value1, char value2, String value3)
c.public void DetermineResult (double value2, int value1, String value3)
d.public int DetermineResult (int x, char y, String z)
e. public void DecideResult (int x, double value2, String z)
2. For the following program, circle "Wrong" if there are any errors on that line, otherwise circle "correct"
public class StaticDemo {
private int i=2;
private static int k=0;
public static void main(String[] args) {
i = 20; //wrong or correct
int x = method2(1,2); //wrong or correct
method1(); //wrong or correct
}
public void method1() {
i += k = method2(1,2); //wrong or correct
}
public static int method2(int x, int y) {
return (x + y);
}
Explanation / Answer
1. Signature of method is
DetermineResult(int, char, String)
2. public int DetermineResult (int x, Char y, String z)
Have different number of arguments.
2) Have same number of arguments but their types are different.
3) Have both different numbers of arguments with a difference in their types
2.
public class StaticDemo
{
private int i=2;
private static int k=0;
public static void main(String[] args)
{
i = 20; //wrong or correct
int x = method2(1,2); //wrong or correct
method1(); //wrong or correct
}
public void method1()
{
i += k = method2(1,2); //wrong or correct
}
public static int method2(int x, int y)
{
return (x + y);
}
}
//
i =20;
method1();
are wrong declaration due to non- static variable and method
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.