Comment on Tutorial - Abstract classes in Java By Kamini



Comment Added by : Pulkit Malviya

Comment Added at : 2012-08-26 14:56:18

Comment on Tutorial : Abstract classes in Java By Kamini
Hello to Every one!! :-),HERE I'AM NOT WRITING A CODE BECZ IT WILL TAKE A LOTS OF SPACE,SO I'AM JUST GIVING EXPLANATIONS TAT WAT IS ABSTRACT CLASS,BUT AFTER READING DIS EXPLANATIONS ALSO IF NYONE WILL NOT UNDERSTAND THEN AFTER TAT I'LL WRITE D CODE ALSO,so firstly we'll go to the "Abstract Method" before "Abstract Class,so wat is Abstract method?? so Method u all know is like a fucntion in C++ or C,just name is changed otherwise no differences r der,so "abstract method is a method without body",an abstract method is written when d same method has to perform different tasks depending on the object calling it,nd "ABSTRACT CLASS is a class tat contains 0 or more abstract methods, i mean in other words for Eg- if we want to calculate the square value in a Java program,so let we took a function named "calculate()" nd class named"Myclass" in a program,nd after tat we provide body for calculate() method,also we took three objects named obj1,obj2,obj3,now after dis u all r already know how to write a program of square value,actualy i'am not concentrating on square value program,i'am concentrating on the "BODY" of calculate() method,dis means as we written a body for calculate() method,so tat it is commonly available to all d objects -obj1,obj2,obj3,means requirements of all d objects is same,i.e "to calculate the square value",but sometimes the requirements of all d objects will be different depending on the objects,for eg-like first object(obj1) wants to calculate square value,second object(obj2) wants the square root value,nd third object(obj3) wants cube value,then wat to do now??its simple,firstly just write a calculate() method in "Myclass",dis means every object wants to calculate something,after tat dont write body for calculate() method,so tat it will not be commonly available to all d objects-obj1,obj2,obj3,so such a method is called as a "Abstract Method",in dis way we write abstract method in Myclass,then it is called as "Abstract Class",now derive sub classes from Myclass,tat means firstly derive sub class Sub1 from Myclass,so tat the calculate() method is available to d sub class,now provide a body for calculate() method in sub1 so tat it calculates square value,//ly we create another sub class Sub2 ,where we write the calculate() method with body to calculate square root value,then we again create d third sub class Sub3 where we write the calculate() method to calculate cube value,in dis way we'll create sub classes,nd after tat in another class u all r already know tat how to create sub class objects to call these classes methods,like Sub1 obj1=new Sub1(); Sub2 obj2=new Sub2();Sub3 obj3=new Sub3(); now after tat these objects will call,like dis- obj1.calculate(4);//calculate square,obj2.calculate(16); // calculate square root,obj3.calculate(3); // calculate cube value,so frnds the main concentration was on the "METHOD BODY",so in short "abstract method is a method without method body nd is written when the same method has to perform different tasks depending on the object" nd "abstract class is a class tat contains abstract methods",thanx,i'am waiting for ur comments... :-)

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. How to write data from keyboard to a file in java?
View Tutorial          By: Ashish Ranjan at 2011-07-13 01:04:38

2. Does memmove care if the source is bytes and the d
View Tutorial          By: Paul at 2012-07-20 11:59:32

3. Your page does not show the text in the proper col
View Tutorial          By: Warron at 2013-04-04 17:50:22

4. This example is very good, but it doesnt work in M
View Tutorial          By: soma at 2010-04-13 04:34:00

5. It would he helpful to know difference between a l
View Tutorial          By: Tosh at 2012-04-28 18:00:20

6. can we print only second by using the date functio
View Tutorial          By: mukesh kumar at 2011-07-27 02:31:02

7. MSComm1.Settings="9600,n,8,1"

View Tutorial          By: ali at 2012-02-25 21:52:21

8. It is very simple and understandable tutorial, the
View Tutorial          By: Syed Turab at 2010-03-09 07:27:15

9. really really very good
thanks all
a

View Tutorial          By: bade3 at 2010-01-01 18:52:15

10. Incomplete article; Singleton session bean? And re
View Tutorial          By: vaibhav sakpal at 2013-08-29 07:35:37