• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about abstract method and class

 
y bin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to determine if the following is correct.
Anybody could discuss it with me?

1,the abstract method's announce need not {} ?
but the abstract method in the abstrct class may have contents({})

2, the abstrct class can't be instantiated, how can I say it has constructor? what is the construtor use?
 
Leo Deegan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there, y.

1. An abstract method cannot have a block for its body (that is, it can only use a semicolon and cannot use { }).

2. An abstract class can be instantiated, provided its abstract methods are implemented when the class is instantiated. For instance,

public abstract class Abc {
public astract boolean foo();
}

can be instantiated like this:

Abc abc =
new Abc() {
public boolean foo() {
return false;
}
};

One reason for providing a constructor for an abstract class is that its subclasses may take advantage of the constructor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic