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. Hi IDK,
You close any applications includin

View Tutorial          By: Steven at 2008-12-30 03:14:33

2. The code gives the following exception :-
<

View Tutorial          By: waqar at 2012-07-26 17:02:07

3. it's real nice explanation
View Tutorial          By: Shreya at 2010-09-10 11:24:11

4. Thanks for example..
But I have the same p

View Tutorial          By: Lina at 2009-05-02 13:23:33

5. Hi Sir...
sir i am a student and I am worki

View Tutorial          By: shanthi at 2013-03-22 11:01:15

6. New thread: Thread[One,5,main]
How is the s

View Tutorial          By: Venkatesh at 2013-04-21 07:06:15

7. good!
View Tutorial          By: rey.ryan at 2009-03-14 05:49:28

8. hi can any one help me how i can install javax.co
View Tutorial          By: Jewel at 2008-02-26 21:52:17

9. Hi, a have a problem using bsearch. i need return
View Tutorial          By: Daniel at 2009-03-30 04:11:13

10. Please some one send me the 6th program developed
View Tutorial          By: mounika at 2008-04-25 02:49:56