What is the difference between call by value and call by reference in Java?
Can a method call itself directly or indirectly in Java?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
What will be the output of the following code?
public class MyClass {
public static void main(String[] args) {
int x = 10;
int y = modify(x);
System.out.println(x + y);
}
public static int modify(int value) {
value += 5;
return value;
}
}
What will be the output of the following code?
public class MyClass {
public static void main(String[] args) {
int x = 5;
int y = 10;
swap(x, y);
System.out.println(x + " " + y);
}
public static void swap(int a, int b) {
int temp = a;
a = b;
b = temp;
}
}
What is the difference between a method declaration and a method definition in Java?
What will be the output of the following code?
public class MyClass {
public static void main(String[] args) {
int result = multiply(3, 4);
System.out.println(result);
}
public static int multiply(int a, int b) {
if (b == 0) {
return 0;
} else {
return a + multiply(a, b - 1);
}
}
}
What is the difference between method overloading and method overriding in Java?
Which of the following statements about methods in Java is correct?
What is the purpose of the "static" keyword in Java method declarations?
Which of the following is true about passing arguments by value in Java?
What is the output of the following code snippet?
public class Example {
public static void main(String[] args) {
int result = multiply(3, 4);
System.out.println(result);
}
public static int multiply(int a, int b) {
return a * b;
}
}
What is the output of the following code snippet?
public class Example {
public static void main(String[] args) {
String str = "Hello";
updateString(str);
System.out.println(str);
}
public static void updateString(String s) {
s += " World";
}
}
What is the output of the following code snippet?
public class Example {
public static void main(String[] args) {
int x = 5;
updateValue(x);
System.out.println(x);
}
public static void updateValue(int value) {
value = value + 1;
}
}
What is the output of the following code snippet?
public class Example {
public static void main(String[] args) {
int result = sum(3, 4);
System.out.println(result);
}
public static int sum(int a, int b) {
return a + b;
}
public static double sum(double a, double b) {
return a + b;
}
}
Which of the following methods can be used to calculate the factorial of a number in Java?