• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is the purpose for allowing local variables as abstract ?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic