File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes what is the purpose for allowing local variables as abstract ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the purpose for allowing local variables as abstract ?" Watch "what is the purpose for allowing local variables as abstract ?" New topic
Author

what is the purpose for allowing local variables as abstract ?

Phone Myat Kyaw
Ranch Hand

Joined: Dec 26, 2008
Posts: 31
Hi, I'm truly sorry if my question has been answered already, but that thing just came into my mind.

As the topic, what is the main purpose for allowing local variables as abstract ? Is it just solely for abstract class/method so that programmers can leave such variables with no initialization ?

What I understand is, instance variables are automatically assigned to default values if no initialization but for local, we must declare their values explicitly. So, the main purpose for local can be abstract is, just for abstract class/method or is there other reasons ?

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Local variables cannot be abstract. The only modifier allowed for local variables is final

As a matter of fact, the abstract abstract modifier is used for classes or methods respectively, not for variables.


JDBCSupport - An easy to use, light-weight JDBC framework -
Phone Myat Kyaw
Ranch Hand

Joined: Dec 26, 2008
Posts: 31
Sebastian Janisch wrote:Local variables cannot be abstract. The only modifier allowed for local variables is final

As a matter of fact, the abstract abstract modifier is used for classes or methods respectively, not for variables.


Hi, thanks for your quick response, but local variables certainly can be abstract.



That's why I'm wondering why it's allowed, no idea how it's useful in what situation except abstract class/method
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3007
    
    9
Phone Myat Kyaw
Ranch Hand

Joined: Dec 26, 2008
Posts: 31



some mysterious thing occurs ? I use NetBeans 6.7 and Java 1.6.0_13 on Mac. I swear by god that I never change, just compile and get this successful message.
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
Just tried with Eclipse Ganymede using Java 1.6.0_14 on Ubuntu and it does not compile.

I get the exact same error as Mike.

Have you tried compiling from the command line/terminal? Perhaps NetBeans is suppressing a warning and you are not running the class you think you are running.


SCJP6
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I was just about to say that NetBeans maybe has a precompiler that strips out things that don't make sense ...
Phone Myat Kyaw
Ranch Hand

Joined: Dec 26, 2008
Posts: 31
Jason Irwin wrote:Just tried with Eclipse Ganymede using Java 1.6.0_14 on Ubuntu and it does not compile.

I get the exact same error as Mike.

Have you tried compiling from the command line/terminal? Perhaps NetBeans is suppressing a warning and you are not running the class you think you are running.


Hi Jason, you are absolutely correct, as I've tried in cmd and get the same error.
Hmm, why NetBeans is not giving such error ? Is it like NetBeans is not as reliable as Eclipse or am I missing something?

For the thing you said that it's not the class that I think it's, could not be. Because it's showing other parts of the program and so, I'm pretty sure it's as what it should be. In fact, I'm just doing as a practice myself for my SCJP 6 exam which is on 14th next month, studying the Inner Class related question using "SCJP 6 Study Guide by Kathy Sierra & Bert Bates". This is my full code for the whole program.



anyway, thanks a lot to you guys
really appreciate your very fast and helpful response + advice
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
What I means was, if you had just added "abstract", then you could actually be running an older .class accidentally.

Why NetBeans doesn't report it beats me - I have never used NetBeans.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the purpose for allowing local variables as abstract ?