This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1What do you mean by Method Overloading in Java?
Option C
In Java, a method is a block of code that performs a specific task. One of the core features of Java is Polymorphism, which allows objects or methods to take multiple forms.
Method overloading is a type of compile-time polymorphism where a class has two or more methods with the same name but different parameter lists.
It allows programmers to use the same method name for related actions, improving readability and organization.
class Calculator {
int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
double add(double a, double b) {
return a + b;
}
}
public class Main {
public static void main(String[] args) {
Calculator calc = new Calculator();
System.out.println(calc.add(15, 25));
System.out.println(calc.add(15, 12, 30));
System.out.println(calc.add(2.5, 7.5));
}
}
Q: 2What is Polymorphism in Java?
Option A
The word Polymorphism means Many Forms. It allows objects or methods to take multiple forms, enabling flexibility and reusability in code. Polymorphism improves code flexibility, readability, and maintainability. There are two main types of polymorphism in Java:
Compile-Time Polymorphism (Method Overloading):
Runtime Polymorphism (Method Overriding):
You have reached the end of this topic. Continue learning with the next topic below.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.