Java Intermediate

0% completed

Previous
Next
Quiz
Question 1
What is polymorphism in Java?
A
The ability of an object to take on many forms.
B
The ability of a class to inherit properties from multiple classes.
C
The process of hiding the internal state of an object.
D
The technique of reusing code in different parts of a program.
Question 2
Consider the following code snippet:
class Calculator {
    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }
}
public class Test {
    public static void main(String[] args) {
        Calculator calc = new Calculator();
        System.out.println(calc.add(5, 3));
    }
}
What concept does this code demonstrate?
A
Method Overriding
B
Dynamic Binding
C
Method Overloading
D
Encapsulation
Examine the following code snippet:
class Shape {
    void draw() {
        System.out.println("Drawing Shape");
    }
}
class Circle extends Shape {
    void draw() {
        System.out.println("Drawing Circle");
    }
}
public class Test {
    public static void main(String[] args) {
        Shape s1 = new Circle();
        s1.draw();
    }
}
What will be printed?
A
Drawing Shape
B
A compile-time error occurs.
C
null
D
Drawing Circle

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next