+ 3

Can anyone tell me the use of 5th line?

https://code.sololearn.com/cbaGIRxiq0vp/?ref=app //Copied this program from a video tutorial

7th Jun 2021, 11:32 AM
Atul [Inactive]
16 Answers
+ 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
7th Jun 2021, 11:42 AM
Abhiyantā
Abhiyantā - avatar
+ 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
7th Jun 2021, 12:12 PM
Abhiyantā
Abhiyantā - avatar
+ 3
Atul , Nothing will happen, You can say that it's for devlopers so that we all can know that this method is overriden
7th Jun 2021, 12:38 PM
Abhiyantā
Abhiyantā - avatar
+ 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
7th Jun 2021, 11:42 AM
Roderick Davis
Roderick Davis - avatar
+ 2
what do you mean? Public means you can access it anywhere, String tells the return type of function name toString()
7th Jun 2021, 12:43 PM
Abhiyantā
Abhiyantā - avatar
+ 2
Atul Well, if you don't want functions means its not overriding!
7th Jun 2021, 1:30 PM
Abhiyantā
Abhiyantā - avatar
+ 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.
7th Jun 2021, 1:32 PM
Soumik
Soumik - avatar
+ 2
You're welcome Atul bro šŸ‘
7th Jun 2021, 2:33 PM
Soumik
Soumik - avatar
+ 1
Emma Watson not about the annotation @Override public String toString() { return "Radius cannot be negative!";} ///These lines
7th Jun 2021, 12:31 PM
Atul [Inactive]
+ 1
Rishav Tiwari from this video only I learnt this concept šŸ¤£ This program is also taken from this channel's video
7th Jun 2021, 12:33 PM
Atul [Inactive]
+ 1
Soumik thanks your answer. Now I understood the concept
7th Jun 2021, 1:40 PM
Atul [Inactive]
+ 1
Emma Watson Rishav Tiwari Roderick Davis thank you all I take time to understand some concepts
7th Jun 2021, 1:42 PM
Atul [Inactive]
0
But what if I remove this line?
7th Jun 2021, 12:00 PM
Atul [Inactive]
0
Rishav Tiwari Public to string method also? My main motive of this question is this only
7th Jun 2021, 12:40 PM
Atul [Inactive]
0
Haan can we remove that function? Do the program will.work as the asame after removing this function?yes/no
7th Jun 2021, 12:56 PM
Atul [Inactive]
- 1
The answer is in the video tutorial itself.
8th Jun 2021, 2:30 PM
Parth Shendge