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



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. if the two StringBuffer object contain same String
View Tutorial          By: Avinash kumar at 2011-11-09 11:16:19

2. Controlling Page Navigation in JSF - Static and Dy
View Tutorial          By: chip at 2010-10-07 05:16:14

3. 510
1020
2040
4080
816

View Tutorial          By: sky at 2010-07-17 06:54:46

4. i want to learn j2me basic to ....
View Tutorial          By: gopiraj at 2012-12-21 11:52:01

5. Can please send me codes to pass strings or text f
View Tutorial          By: bryan at 2009-12-29 05:59:21

6. great thanks a lottttttttttttttttt
View Tutorial          By: reshma at 2011-06-13 04:35:44

7. This tutorial is very much useful for me to develo
View Tutorial          By: R. Lawrance at 2009-07-26 22:03:15

8. good one
View Tutorial          By: thyagesh at 2011-12-06 05:06:27

9. please give example code with defined variable.
View Tutorial          By: shajjad at 2011-02-13 20:56:09

10. date span progarm sorce code in jsp by using strin
View Tutorial          By: prudhvi at 2013-01-27 13:55:09