Abstract body

Can we declare abstract body ? Explain with simple example and the situation you would use ?

Showing Answers 1 - 9 of 9 Answers

krishna

  • Jan 19th, 2012
 

Code
  1.     public abstract class MissingMethodBodyOrDeclareAbstractSolution

  2.     {

  3.     public void display(String message)

  4.     {

  5.     System.out.println(message);

  6.     }

  7.     public abstract void display();

  8.     }

  9.  

  10.  

  Was this answer useful?  Yes

krishna

  • Jan 19th, 2012
 

Here, a ; (semicolon) is given after the method header of the first display method (with parameter). And for the second display method, keyword ‘abstract’ is not stated in the header and it doesn’t have any body also. Here it is to be noted that if a class contains an abstract method, the class must also be abstract.

Code
  1.     public abstract class MissingMethodBodyOrDeclareAbstractSolution

  2.     {

  3.     public void display(String message)

  4.     {

  5.     System.out.println(message);

  6.     }

  7.     public abstract void display();

  8.     }

  9.  

  10.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions