➢ When the no-argument constructor of ClassA is called in the main method of classB, a is pre- incremented by 1 so a=1, which is then printed. ➢ When the constructor of ClassA is called in the main method of ClassB with 3 as parameter, the second constructor is invoked which assigns the value of a to 3 a=0+1=3; ➢ The value of a in the second print method is zero because a is an instance variable and is set to 0 every time an instance is created.
➢ There is no main method in this program, so program will not be executed.
➢ Since there is a no explicitly defined constructor, the default no-argument constructor is called, but by constructor chaining the default constructor of Apple Class calls the no-argument super class constructor (Fruit Class), but there is no no-argument constructor explicitly written for fruit class. Immutable object is an object whose contents cannot be changed once the object has been created. A class with private data fields, no mutator and no accessor methods that can return a reference to a data field that is mutable will be an immutable class, and its instance will be immutable. For example, the String Class. For Example;