Quiz Space

Programming Concepts using Java · Quiz 1 · 25 Feb 2024 · January 2024 term

Question 14: Consider the code given below. Choose the correct option.

Question 14

+8 marksOne correct option

Consider the code given below.

java
class Shape {
public void draw() {
System.out.println("Drawing a shape");
}
}
class Rectangle extends Shape {
public void draw() {
System.out.println("Drawing a rectangle");
}
}
class Square extends Rectangle {
public void draw() {
System.out.println("Drawing a square");
}
public void color() {
System.out.println("Square is colorful");
}
}
public class TestShapes {
public static void main(String[] args) {
Shape s = new Rectangle();
Rectangle r = new Square(); // LINE 1
s.draw();
r.color(); // LINE 2
}
}

Choose the correct option.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 14 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 1 paper sat on 25 Feb 2024, in the January 2024 term (IIT M DIPLOMA AN2 EXAM QDD2 25 Feb 2024). It carries 8 marks.

More questions from this paper

  1. Q1Which of the following statements is/are true about activation records?
  2. Q2Figure question
  3. Q3Consider the code given below. Choose the correct option.
  4. Q4Consider the Java code given below. Choose the correct option regarding the given code.
  5. Q5Consider the Java code given below. Choose the correct option.
  6. Q6Consider the Java code given below. Choose the correct option.
  7. Q7Consider the code given below. Choose the correct option to fill in place of CODE BLOCK so that the output is: Processi…
  8. Q8Consider the Java code given below. What will the output be?
  9. Q9Consider the Java code given below. What will the output be?
  10. Q10Consider the Java code given below. Choose the correct option to fill in the CODE SEGMENT so that the output is:\ Toyot…
  11. Q11Consider the following code: Choose the correct option to fill in the CODE SEGMENT so that the output is:\ Animal makes…
  12. Q12Consider the code given below that checks whether two Persons are the same. Method equals is overridden to compare two …
  13. Q13Consider the Java code given below. Choose the correct option regarding the above code.
  14. Q15Consider the Java code given below. Choose the correct option.