nirjari patel wrote:1) What is method overwriting ? How is it different from overriding and overloading ?
The term means nothing in
Java. Wherever you read it, they probably meant overriding, and misspelled it.
nirjari patel wrote:2) In methoid overriding, we can change definition of method and in method overloading, we can change method parameters. Buit in neither case, we can change access modifier or return type.
That's not true. An overloaded method can have a completely different access modifier, and a completely different return type. An overriding method can have a different access modifier, if the new modifier is more public than the old one. Default can be overridden with protected or public, and protected can be overridden with public. And the overriding method can have a different return type, provided the new return type is a subtype of the old one. So a method that returns Object can be overridden with a method that returns
String. But a method that returns String cannot be overridden with a method that returns Object. That's because String is a subtype of Object, and Object is not a subtype of String.
nirjari patel wrote:Now in case if wekeep the same method name and alter access modifier and return type , what is it called ? Is it some other operation like overriding or overloading ? Or will that be compilation error ?
It's overriding. But if you violate the rules of overriding that I just stated, you will get a compile error.