Methods
- What is the output of this program?
class calclution
{
int p;
int q;
calclution(int K, int L)
{
p = K;
q = L;
}
void calc(calclution n)
{
n.p *= 2;
n.p /= 2;
}
}
public class Result
{
public static void main(String args[])
{
calclution obj = new calclution(50 , 20);
obj.calc(obj);
System.out.println(obj.p + " " + obj.q);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Output: 50 20
- Which of these can be used to differentiate two or more methods having same name?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Return type of method, Number of parameters and Parameters data type can be used to differentiate two or more methods having same name.
- What is the process of defining more than one method in a class differentiated by parameters?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example – int volume(int length, int width) & int volume(int length , int width , int height) can be used to calculate volume.
- Which of these is the method which is executed first before execution of any other thing takes place in a program?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
If a static method is present in the program then it will be executed first, then main will be executed.
- What is the output of this program?
class method
{
int p;
double q;
void add(int n1 , int n2)
{
p = n1 + n2;
}
void add(double n3 , double n4)
{
q = n3 + n4;
}
method()
{
this.p = 0;
this.q = 0;
}
}
public class method_overload
{
public static void main(String args[])
{
method obj = new method();
int n1 = 5;
double n2 = 7.5;
obj.add(n1, n1);
obj.add(n2, n2);
System.out.println(obj.p + " " + obj.q);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Output: 10 15.0