Assignment 2
Assignment 2
Assignment (2)
St. Name: (Total Marks: 10) St. Reg.#:
Q1: Explain why Java and Ada treat mixed-mode expressions differently, and
analyze the implications of this difference using the following examples:
What would happen in Python, and why does its approach differ?
x=0
print("Valid")
else:
print("Invalid")
Why does this code not result in a runtime error? Modify the code to avoid relying
on short-circuit evaluation for safety.
Q3: In Python, implement a class Vector that supports addition (+) and scalar
multiplication (*). Write an overloaded operator for each operation and demonstrate
its usage with examples.
int x = 0;
System.out.println("Valid");
} else {
System.out.println("Invalid");
Explain the behavior of this code. How would removing short-circuit evaluation (&
instead of &&) change the outcome?
result = 10 - 2 ** 3 / 4 + 5
How would changing the exponentiation operator (**) to left-associative affect the
result?