• 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

Abstract methods don't have a body- confused

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, abstract methods don't have a body and should end in a semicolon when described in an abstract class, but one big doubt.

What happens if you do declare it this way?

public void jump();

I tried it and there is NO COMPILER ERROR

Also, if I try marking a method as abstract and don't mark the class as abstract there is no compiler error again. My program runs fine.

Am I doing something wrong???
Please help!!

Thanks,
Nicole.
 
Xyz Abc
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help!!!
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nicole!!
I checked your doubt on my Java platform. I think you're doing something wrong or missing something, because when you declare like this,

public void jump();

in a normal or abstract class, you're BOUND to get a COMPILER ERROR like this:


Also if you don't declare a class abstract having a abstract method you get a COMPILER ERROR like this:

Check it out once again!!
 
Xyz Abc
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know the weirdest thing is, its still compiles fine
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Plese send the complete source code which you are trying to compile
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nicole!!
Try compiling both these classes.
Eg1:


Eg2:


If this is what you mean, then can you check whether these COMPILE??
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicole Facompre:
You know the weirdest thing is, its still compiles fine



Please copy paste the code here...
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi palla,

both example that you gave won't compile..

so it should be like this only ..

Ex1.
public abstract class A{

public abstract void method1();
}

OR

public abstract class A{

public void method1(){
}
}
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi palla,

both example that you gave won't compile..

so it should be like this only ..

Ex1.
public abstract class A{

public abstract void method1();
}

OR

public abstract class A{

public void method1(){
}
}
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi palla,

both example that you gave won't compile..

so it should be like this only ..

Ex1.
public abstract class A{

public abstract void method1();
}

OR

public abstract class A{

public void method1(){
}
}
 
Xyz Abc
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually figured out what is wrong with my Eclipse. It shows the error happening in the Problems tab but also compiles and prints something to the console. Is this a problem with my compiler?
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nicole,

When you ran the program, did you get a dialog that said:

"Errors exist in required project(s):"
...
"Proceed with Launch?"

This means that there is a problem in your code, but Eclipse will try to run it anyway. Sometimes, it *will* run, but can be misleading (obviously).

Aloha,
Doug

-- Nothing is impossible if I'mPossible
 
Xyz Abc
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I have suppressed the option to show that dialog box sometime back

Anyway I know now!!
reply
    Bookmark Topic Watch Topic
  • New Topic