appreciated jon. Like I said I just started coding in Java so style advice is also helpful.
So basically you need a no=arg constructor in a class if you want to inherit from it?
I'm also not familiar with the super() constructor but I added a no-arg constructor and now it compiles fine.
20 Replies - 1354 Views - Last Post: 18 September 2012 - 03:57 PM
#17
Re: final vs. const
Posted 18 September 2012 - 09:04 AM
just to explain this in terms of C++, 'const' used after a method declaration means that that method cannot modify 'this' and thus can be used from constant pointers and constant references. As far as I know Java doesn't have const correctness or const types so this idea doesn't even apply. you would just drop the const at the end.
also, 'final' applied to a method in java is similar to the default behavior of methods in C++. I won't go into the specifics but the 'virtual' keyword allows a C++ method to act more like a Java method.
also, 'final' applied to a method in java is similar to the default behavior of methods in C++. I won't go into the specifics but the 'virtual' keyword allows a C++ method to act more like a Java method.
This post has been edited by ishkabible: 18 September 2012 - 09:49 AM
#18
Re: final vs. const
Posted 18 September 2012 - 09:09 AM
just out of curiousity but why the conversion?
#19
Re: final vs. const
Posted 18 September 2012 - 09:42 AM
The const and goto keywords were carried over from C++. You get a nice slap on the wrist for using them though.
#20
Re: final vs. const
Posted 18 September 2012 - 10:07 AM
There's really no such thing as "const correctness" in Java. You use a method and there's never an explicit guarantee the state won't be changed.
The final for variables means you only get to assign it once. If it's object level, it must be in the constructor. In this sense, it's pretty much identical to a const variable declaration in a C++ class.
The final for method is different. It means subclasses don't get to override it. It's roughly the opposite of virtual in C++.
The final for variables means you only get to assign it once. If it's object level, it must be in the constructor. In this sense, it's pretty much identical to a const variable declaration in a C++ class.
The final for method is different. It means subclasses don't get to override it. It's roughly the opposite of virtual in C++.
This post has been edited by baavgai: 18 September 2012 - 10:07 AM
#21
Re: final vs. const
Posted 18 September 2012 - 03:57 PM
|
|

New Topic/Question
Reply





MultiQuote










|