An abstract method is the method which does’nt have any body.
Abstract method is declared with
keyword abstract and semicolon in place of method body.
public abstract void <method name>();
Ex : public abstract void getDetails();
It is the responsibility of subclass to provide implementation to
abstract method defined in abstract class
No, abstract class can have zero abstract methods.
No. A normal class(non-abstract class) cannot have abstract methods.
Abstract classes CAN have non-abstract methods.
abstract class AbstractDemo { // Abstract class
private int i = 0;
public void display() { // non-abstract method
System.out.print("Welcome to Tutorials Point");
}
}
public class InheritedClassDemo extends AbstractDemo {
public static void main(String args[]) {
AbstractDemo demo = new InheritedClassDemo();
demo.display();
}
}
abstract class Language {
// method of abstract class
public void display() {
System.out.println("This is Java Programming");
}
}
class Main extends Language {
public static void main(String[] args) {
// create an object of Main
Main obj = new Main();
// access method of abstract class
// using object of Main class
obj.display();
}
}
Yes, we can. An abstract class can have both abstract and non-abstract methods