Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


When you declare a method as abstract method ?

Answers were Sorted based on User's Feedback



When you declare a method as abstract method ?..

Answer / ankur pandya

When we want to design such a method which is different for
every of its child class, means all the subclass has that
method with different behavior, then we declare the method
as ABSTRACT METHOD.
for eg.

------------------------------------------------------------

// file name "AbstractMethodDemo.java"

abstract class MyAbstractClass {
abstract void myAbstractClassMethod1(); // defination
done in DerivedClass class
void myAbstractClassMethod2(){
System.out.println("myAbstractClassMethod2()
method called from Parent Class..");
}
}

class DerivedClass1 extends MyAbstractClass {
void myAbstractClassMethod1(){
System.out.println(" myAbstractClassMethod1()
method Called form Derived Class-1..");
}
}

class DerivedClass2 extends MyAbstractClass {
void myAbstractClassMethod1(){
System.out.println(" myAbstractClassMethod1()
method Called form Derived Class-2..");
}
}

public class AbstractMethodDemo {
public static void main(String[] args) {

DerivedClass1 obj1 = new DerivedClass1();
obj1.myAbstractClassMethod1();
obj1.myAbstractClassMethod2();

DerivedClass2 obj2 = new DerivedClass2();
obj2.myAbstractClassMethod1();
obj2.myAbstractClassMethod2();

}
}

---------------------------------------------------------

Here myAbstractClassMethod1() is abstract because I want to
change its behaviour as Base classes, But
myAbstractClassMethod2() is not declared Abstract because I
want to keep its behaviour same for every base class.

Ans obvious, Abstract Method must be declared in Abstract Class.

I hope the defination is clear now..

Is This Answer Correct ?    9 Yes 0 No

When you declare a method as abstract method ?..

Answer / shadow

When i want child class to implement the behavior of the
method.

Is This Answer Correct ?    5 Yes 2 No

Post New Answer

More Core Java Interview Questions

What is difference overloading and overriding?

0 Answers   Cyient,


What is arrays fill in java?

0 Answers  


What modifiers can be used with a local inner class?

2 Answers  


Can we have a try block without catch block?

0 Answers  


What are void pointers?

1 Answers  


Explain the importance of join() method in thread class?

0 Answers  


HOW TO PRINT A NO IN WORDS USING WHILE LOOP THE NO WILL BE PRINTED WHEN IT WILL BE IN THE RANGE BETWEEN 1 AND 3?

1 Answers  


What is string variable?

0 Answers  


Why java is free from garbage values??

4 Answers  


Is set ordered in java?

0 Answers  


Brief the life cycle of an applet.

1 Answers  


What is a thin-client application?

5 Answers   Adobe,


Categories