d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > @override
Add Reply New Topic New Poll
Member
Posts: 5,913
Joined: May 6 2009
Gold: 0.00
Mar 9 2015 04:02am
the fuck is override?
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Mar 9 2015 06:16am
You're telling the compiler that you want this function to override the other function with the same name.

IE. you @override the toString method as it prints out ugly text with lots of extra unneeded characters. So I would do:

public class Chevy extends Cars{};


@override

public toString(takes in whatever you're print out or can be accessed via accessor methods){

-insert edits you want to make here like removing {} characters from start/end etc and print out your object(s).
}

When you call the toString method on chevy cars it'll print out whatever is in your overridden toString instead of the generic toString.
Member
Posts: 5,913
Joined: May 6 2009
Gold: 0.00
Mar 10 2015 07:16am
Quote (HoneyBadger @ Mar 9 2015 01:16pm)
You're telling the compiler that you want this function to override the other function with the same name.

IE. you @override the toString method as it prints out ugly text with lots of extra unneeded characters. So I would do:

public class Chevy extends Cars{};


@override

public toString(takes in whatever you're print out or can be accessed via accessor methods){

-insert edits you want to make here like removing {} characters from start/end etc and print out your object(s).
}

When you call the toString method on chevy cars it'll print out whatever is in your overridden toString instead of the generic toString.


ok thanks buddy
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 10 2015 02:55pm
http://docs.oracle.com/javase/tutorial/java/annotations/predefined.html
https://docs.oracle.com/javase/8/docs/api/java/lang/Override.html

Quote
While it is not required to use this annotation when overriding a method, it helps to prevent errors. If a method marked with @Override fails to correctly override a method in one of its superclasses, the compiler generates an error.

Go Back To Programming & Development Topic List
Add Reply New Topic New Poll