keyword publ CITY COLLEGE OF TECHNOLOGY CST3513 MIDTERM GOOD LUCK ID Nam Assume
ID: 3737893 • Letter: K
Question
keyword publCITY COLLEGE OF TECHNOLOGY CST3513 MIDTERM GOOD LUCK ID Nam Assume that the following codes are correctly inserted into a program and a variables are properly declared. You are not allowed to run any program in the Points: 2 1. State whether each of the following is true or false. a) Keyword public is a(n) access modifier. b) The following methods are overloaded:_ A. public int max (int a, int b).. B. publie double max (double a, double b)... Points: 2 2. Find and correct the error(s) in each of the following segments of code: a) public static void f( float a); float a; System.out.println( a); b) public static int sum ( int x, int y) int result; result x+ y; System.out.println(j);
Explanation / Answer
1)state whether each of the followings are true/false
a)true
public is the acess modifier which have very broad access in code.
b)true
These methods are overloaded as they accept different data type
vars as parameter.
2)Find and correct the error(s)
a)
public static void f(float a) {
float a;
System.out.println(a);
}
error-> duplicate varible a as same var name taking as function parameter
corrcted:
public static void f(float a) {
System.out.println(a);
}
b)
public static int sum(int x,int y) {
int result;
result=x+y;
}
System.out.println(result);
error 1->print statement outside of the methods
error 2->no return statement , only void method does not have return
corrected:
public static int sum(int x,int y) {
int result;
result=x+y;
System.out.println(result);
return result;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.