Object cant be created for abstract class to directly access the members of the abstract class. In order to access the members of the abstract class, we've to create a subclass for abstract class and implement the abstract methods of abstract class. We can then access the inherited abstract and non-abstract methods of abstract class by creating an object for subclass.
Lets implement this on Eclipse IDE:
1.Create abstract class 'Superclass' containing abstract and non-abstract methods as shown below:
So, In order to access to access the abstract and non-abstract methods of abstract class, we've to create a subclass for abstract class and create an object for subclass to access the inherited abstract and non-abstract methods of abstract class as shown below:
4. Create subclass 'Subclass' for 'Superclass' as shown below:
7. Observe that the output is displayed in the console as shown below:
Click here to download the project containing the class files used in this post (You can download the project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
No comments:
Post a Comment