Comment on Tutorial - Abstract classes in Java By Kamini



Comment Added by : srini

Comment Added at : 2012-08-03 14:42:58

Comment on Tutorial : Abstract classes in Java By Kamini
Hi Zishan

this is useful for you,

Abstract classes cannot be instantiated directly. Declaring a class as abstract means that you do not want it to be instantiated and that the class can only be inherited. You are imposing a rule in your code.

If you extend your Parent/Child relationship example further to include a Person class then it would make good sense for Person to be abstract. Parent is a concrete idea and so is child. Person is an abstract concept in reality as well as in code.

One benefit is that you explicitly define and protect the idea of the abstract class. When you declare a class as an abstract there's no way that you or anyone else using your code uses it incorrectly by instantiating it. This reasoning is similar to why we specify functions and fields as public, private or protected. If you declare a function or member as private you are in effect protecting it from improper access from client code. Privates are meant to be used within the class and that's it. Abstract classes are meant to be inherited and that's that.

Now, do you have to use abstract classes and define functions and fields as private instead of public? No, you don't. But these concepts are provided to help keep code clean and well-organized. The abstract class is implemented in all object-oriented languages to my knowledge. If you look around you will see that C++, C#, VB.NET etc. all use this concept.


View Tutorial



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Also note that for reverse ordering, If you have a
View Tutorial          By: Dwight at 2011-07-13 22:13:45

2. sir , i'm doing BCA . I want to learn more about
View Tutorial          By: gayatri patil at 2012-08-18 10:08:32

3. 1. Performance

Object pooling provi

View Tutorial          By: sonia at 2013-09-21 20:22:49

4. Hi All..
Wen i'm running the code..the foll

View Tutorial          By: mounika at 2008-04-26 14:27:30

5. Hi,

I am new to html, and javascrip

View Tutorial          By: Tom Theriault at 2010-12-14 14:54:09

6. site is very good explanation is very clear throug
View Tutorial          By: sridevi at 2013-03-20 15:26:29

7. Hi Steve.
I have two applications; 1 listen

View Tutorial          By: Victor at 2010-08-18 01:22:49

8. hi guys,

i want some

View Tutorial          By: THANGA at 2012-03-19 15:24:38

9. it is very good service.
View Tutorial          By: rajesh at 2009-11-14 02:48:18

10. Hi, If any body was able to send the message suces
View Tutorial          By: Pradeep Singh Chouhan at 2011-03-02 23:03:05