+ 3
Can anyone tell me the use of 5th line?
https://code.sololearn.com/cbaGIRxiq0vp/?ref=app //Copied this program from a video tutorial
16 Respostas
+ 9
5th line @Override Tells that you are overriding a method from a class.
Function overridingĀ is a feature that allows us to have a sameĀ functionĀ in child class which is already present in the parent class. A child class inherits the data members and memberĀ functionsĀ of parent class, but when you want toĀ overrideĀ a functionality in the child class then you can useĀ function overriding.
credit - beginnersbook
+ 5
Atul instead of asking, why don't you try by removing that line
well this video will help you most - https://youtu.be/DSZI90Db24I
+ 3
Atul ,
Nothing will happen,
You can say that it's for devlopers so that we all can know that this method is overriden
+ 2
The toString method already exist for the string class and it is being overridden to perform a specific function for this code. The @Override is to help the compiler
+ 2
what do you mean? Public means you can access it anywhere, String tells the return type of function name toString()
+ 2
Atul Well, if you don't want functions means its not overriding!
+ 2
The toString() method is defined in the Object class which is the superclass of all classes. When you print any reference data type (array or object), the toString() is automatically invoked. This method returns a string containing the memory location of the array/object on the heap.
But, suppose you have a class Employee and when you print an object of the class, you want to print the employee's salary, age, name. In such a case, you can override the method. For example -
@Override
public String toString() {
return "Name : " + employee.name;
}
The annotation makes sure that the method is overriden correctly.
+ 2
You're welcome Atul bro š
+ 1
Emma Watson not about the annotation
@Override
public String toString() {
return "Radius cannot be negative!";}
///These lines
+ 1
Rishav Tiwari from this video only I learnt this concept š¤£
This program is also taken from this channel's video
+ 1
Soumik thanks your answer. Now I understood the concept
+ 1
0
But what if I remove this line?
0
Rishav Tiwari
Public to string method also?
My main motive of this question is this only
0
Haan can we remove that function? Do the program will.work as the asame after removing this function?yes/no
- 1
The answer is in the video tutorial itself.