In Java, instance variables (fields) must be declared in the class body before they are used. Unlike Python, you cannot dynamically add new instance variables to an object at runtime.
Java requires a constructor method to initialize objects. A constructor has the same name as the class and defines its parameters explicitly, whereas Python uses the __init__ method.
Every Java class inherits from the Object class, which provides default methods like toString() and equals(). Overriding toString() gives more meaningful output when printing objects (similar to Pythonβs __str__).
By default, Javaβs equals() method checks reference equality, just like == for objects. To compare objects based on content (like Fraction values), you must override equals() and call it explicitly.
Java supports inheritance through abstract classes (like Number) and interfaces. Extending an abstract class requires implementing its abstract methods, allowing objects like Fraction to be used where a Number is expected.