Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Methods

 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never really had to use Abstract methods in my coding. I am however, trying to get a jump on the SCJP exam. So, my question is this: What is the fundamental difference between Abstract methods and NON-Abstract methods?
Thanks,
 
Pradeepa Battina
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fundamental difference is that an abstract method has no code and a non abstract method or
a concrete method is one which has code in it.
And the class with an abstract method should be
declared abstract.Any class which extends the abstract class should have methods which override
the abstract methods in its super class or it should be declared abstract.
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you declare an abstract method, so that the implementers or other designers who use this class have to write their code ie concrete code for such methods. ie the functionality in the method is left to the person who would be sub-classing that class. How he does is his business, but he has to... if he wants to subclass that class. if he does not then better declare your class as abstract as well.

Originally posted by Jason Kretzer:
I have never really had to use Abstract methods in my coding. I am however, trying to get a jump on the SCJP exam. So, my question is this: What is the fundamental difference between Abstract methods and NON-Abstract methods?
Thanks,
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when a class that is declared Abstract is subclassed, none of the Abstract methods in the superclass HAVE to be implemented? But if the class were not Abstract then the subclass do HAVE to be implemented.
Is this correct?
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't think you got it.
abstract class A {
void method one();==> note semicolon
void method ok()
{//some-code here}
}
class B extends A {
void method one()===> no semicolon because....
{//put code here}
}
if you don't implement method one in class B then declare class B as abstract.
I hope now its clear
Originally posted by Jason Kretzer:
So when a class that is declared Abstract is subclassed, none of the Abstract methods in the superclass HAVE to be implemented? But if the class were not Abstract then the subclass do HAVE to be implemented.
Is this correct?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic