answersLogoWhite

0


Best Answer

An abstract in java is used to specify that the class/function is not yet complete. When a class in declared as abstract it means that it is not meant to be instantiated (you can't create variables of that type). This is because they are meant to be more of a guideline for other classes. When a class extends an abstract class it must either define all of the abstract methods from the abstract class or it must also be declared as an abstract class itself.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

create shape as an abstract class.............. consider triangle,rectangle,square,.. are the shapes and derive these classes from abstract class................each shapes can have an area for its own... so create area as an abstract method and define this method in each derived class with appropriate formula.........

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Abstraction is an important feature

of Java. It means hiding

complexity i.e. it hides the complex details. Abstract class is used to

provide abstraction.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Abstract method with example in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


Can you call an abstract method from a non abstract method in java?

We can't call (i.e, execute) an abstract method in java because these methods don't contain any code to execute!In some special cases like when an abstract method is overridden in a subclass, and when we are using super class reference variable( which is referring that subclass object), it appears that we are calling abstract method in super class. But actually the code in the subclass method is being executed.Example:abstract class SuperClass{abstract void show(); //abstract method in super class}class SubClass extends SuperClass{void show(){ //show() of SuperClass overridden in SubClassSystem.out.println("SubClass Method");}}class Example{public static void main(String... args){SuperClass sup=new SubClass();sup.show(); //SubClass show() will be executed !!!}}


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)


What is abstraction method in java?

Abstraction in Java or Object oriented programming is a way to segregate implementation from interface and one of the five fundamentals along with Encapsulation, Inheritance, Polymorphism, Class and Object. Abstraction in Java is achieved by using interface and abstract class in Java.


What is Abstract-Interface in java?

All interfaces are abstract.

Related questions

When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


Interface in java?

include all abstract method


Can you call an abstract method from a non abstract method in java?

We can't call (i.e, execute) an abstract method in java because these methods don't contain any code to execute!In some special cases like when an abstract method is overridden in a subclass, and when we are using super class reference variable( which is referring that subclass object), it appears that we are calling abstract method in super class. But actually the code in the subclass method is being executed.Example:abstract class SuperClass{abstract void show(); //abstract method in super class}class SubClass extends SuperClass{void show(){ //show() of SuperClass overridden in SubClassSystem.out.println("SubClass Method");}}class Example{public static void main(String... args){SuperClass sup=new SubClass();sup.show(); //SubClass show() will be executed !!!}}


What do mean by interface in java?

An interface in Java is like an abstract class, but there are no method bodies allowed in it and it has to be declared with the interface keyword. It is Java's way of getting around the Deadly Diamond of Death. Only abstract methods and constants are allowed in it.


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)


How can find the length of a string in java without using fun?

Use length() method. Example: "java".length();


What is Abstract-Interface in java?

All interfaces are abstract.


What is abstraction method in java?

Abstraction in Java or Object oriented programming is a way to segregate implementation from interface and one of the five fundamentals along with Encapsulation, Inheritance, Polymorphism, Class and Object. Abstraction in Java is achieved by using interface and abstract class in Java.


What is the of abatract keyword in java 1.7?

"abstract" is used for a class that is not supposed to be instantiated directly. The reason this is used is because the class is not complete; the details are supposed to be filled out in subclasses (derived classes). An abstract class will usually have one or more abstract methods; a method that is declared by name (to make sure derived classes have this method), but without a method body.


What is overriding method in java with simple example?

ye bohut mushkil sawa lhai


What is overridnig method and overlording method in java?

There is no such thing as overlording in Java.


Subclasses of an abstract class that do not provide an implementation of an abtract method are also abstract?

Yes. Any class that does not provide implementation to all its methods as well as its parent class methods needs to be Abstract. The Java compiler would not successfully compile a class that does not do this.