Author:
Daisy Williams
Oct
16
An abstract class is a class that is partially implemented. It provides design convenience. An abstract class consists of one or more abstract methods that are declared but left unimplemented. It is the responsibility of subclasses that extend an abstract class to implement the unimplemented part of the abstract class. As the implementation of an abstract class is not complete, it is not possible to directly create objects of an abstract class.
A class containing one or more abstract methods must be declared as abstract. However, a class can also be declared as abstract even if it has no abstract methods. An abstract class may also have non-abstract methods.
Author:
Daisy Williams
Sep
14
abstract class Ques0347A{
int x;
int init(){
x = 15;
return x;
}
abstract void disp();
}
public class Ques0347 extends Ques0347A{
void disp(){
int y = init();
System.out.println(y);
}
public static void main(String[] argv) {
Ques0347 ob = new Ques0347();
ob.disp();
}
}
An abstract class can be inherited as same as a simple class by using the extends clause. In the given code, there are two classes named Ques0347A and Ques0347. The Ques0347A class is declared as abstract because it contains a declaration of an abstract method named disp. It also contains an instance variable x and an instance method init().
This is a preview of
What will happen if we inherit an abstract class?
.
Read the full post (183 words, estimated 44 secs reading time)