Quiz Space

Programming Concepts using Java · End Term · 30 Apr 2023 · January 2023 term · Set QPD1-S2

Question 13: Consider the Java code given below. Choose the correct o…

Question 13

+4 marksOne correct option

Consider the Java code given below.

java
class Triangle{
private double base, height;
// Constructor Triangle(double b, double h) to initialize base, height
public double getArea() {
assert base > 0; //LINE 1
assert height > 0; //LINE 2
double area = 0.5 * base * height;
assert area > 0; //LINE 3
return area;
}
}
public class AssertionTest {
public static void main(String[] args) {
Triangle obj = new Triangle(3.0, -4.0);
System.out.println(obj.getArea());
}
}

Choose the correct option when the program is executed as:
java -ea AssertionTest

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

Correct answer

  • D

Question 13 of 23 in the IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 30 Apr 2023, in the January 2023 term (IIT M DIPLOMA ET1 EXAM QPD1 S2 30 Apr 2023). It carries 4 marks.

More questions from this paper

  1. Q1Consider the Java code given below. During execution of Line 14 in the above code, the activation record of which metho…
  2. Q2Consider the following code. What will the output be?
  3. Q3Consider the code given below Choose the correct option.
  4. Q4Consider the code given below that checks whether two laptops are the same. Method equals is overridden to compare two …
  5. Q5Consider the Java code given below, and answer the question that follows: Choose the correct option.
  6. Q6Consider the code given below. What will the output be?
  7. Q7Consider the code given below. What will the output be?
  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 code given below. Choose the correct option.
  11. Q11Consider the code given below. What will the output be?
  12. Q12Consider the code given below.\ Assume that file "data.txt" exists and contains the following text.\ I love my country\…
  13. Q14Figure question
  14. Q15Consider the code given below. What will be the possible output?
  15. Q16Consider the code given below. Choose the correct option to be filled in place of CODE BLOCK so that the output is: Cha…
  16. Q17Consider the code given below. Choose the correct option/s
  17. Q18Consider the Java code given below that prints the recharge time of each charger in a list of chargers. From among the …
  18. Q19Figure question
  19. Q20Consider the code given below. From among the options given below, which are possible outputs of the given code?
  20. Q21Consider the code given below. Identify the appropriate option(s) to fill in the blank at LINE 1, such that the output …
  21. Q22Consider the code given below. If the code given above produces the output: Apples\ Grapes\ Apples\ Grapes What should …
  22. Q23Consider the Java code given below. Choose the correct option(s) to be filled in place of CODE BLOCK so that the progra…