• 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

How does this go pls explain

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends

i am taking my exam this month 23
i need to be clear with few things

can u pls explain this regarding abstract methods

If the method is in a class as opposed to interface then both method and class must be marked abstract

this sounds bit ambigous for me, please kindly explain me
in kathy sierra book of scjp in chapter 2 page 9 its given in exam watch
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means interfaces are implicitly abstract.
Example below shows that interface is not declared abstarct.
This is not case with class.If any method in class is abstarct the class should be defined abstract.Hope this helps.
//TestInterface.java
public interface TestInterface{
public abstract void doNothing() throws Exception;
}
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class AbstractDemo {
public void displayData();
}

If you compile this code you will compile time error as

AbstractDemo.java:2: missing method body, or declare abstract
public void displayData();
^
This means


If the method is in a class as opposed to interface then both method and class must be marked abstract


abstract class AbstractDemo {
public abstract void displayData();
}

If you compile this code you will not get any compile time errors.


as opposed to interface


But if the same is a interface like
interface AbstractDemo {
public void displayData();
}

If you compile this code you will not get any compile time errors because the method displayData() is implicitly abstract.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic