• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

private abstract method

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thre is a question in Jargon that says "an abstract method cannot be private." and the answer is true. but I tried it out like this in an abstract class, it compiles.
private abstract void dd();
is the exam wrong? am I correct?
thanks for clearing my doubts. much appreciated.
chun
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chun,
What compiler version are you using? The JLS §8.4.3.1 states "It is a compile-time error for a private method to be declared abstract."
If you try it under JDK 1.3 you do get the compiler error: illegal combination of modifiers
------------------
Jane Griscti
Sun Certified Java 2 Programmer
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chun,
An abstract method cannot be private. Remember that an abstract method is implemented in a class that extends the abstract class. If an abstract method was private, the child class could not provide the implementation for the method.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
When the method is declared to be abstract its implementation is not in the same class. The class has to be declared abstract and the subclass has to implement this method to provide the functionality.
Declaring a method a private say that we can only use this method in the class in which it is declared ,It is not accessable
from the subclass (or any other class) so we cannot provide the implementation for that method.And we have to declared the subclass as abstract.
So i think ,logically there is no use of those classes.But technically it works.
swati
 
Swati Jambhale
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
When the method is declared to be abstract its implementation is not in the same class. The class has to be declared abstract and the subclass has to implement this method to provide the functionality.
Declaring a method a private say that we can only use this method in the class in which it is declared ,It is not accessable
from the subclass (or any other class) so we cannot provide the implementation for that method.And we have to declared the subclass as abstract.
So i think ,logically there is no use of those classes.But technically it works.
swati
 
Chun Wang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using an OLD compiler. jdk 1.1. so I guess it is the compiler that gives me the misconception. thanks for all your help.
chun
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic