Is it possible to make an abstract class a child of normal class? Please answer with a code or a scenario if it is possible. like this. class A { }
abstract class B extends A {
Yes, it is entirely possible. Being made abstract does not prevent it from extending from a concrete class.
The general idea of abstract class is to provide common properties and behaviours (especially behaviours to be implemented individually in its subclass). However being made abstract only prevent itself from instantiation.
It is still logical if I want to inherit some properties from a concrete class to an abstract class even though this scenario is rare.
A simple (or rather curde) example:
In my honest opinion this is a very uncommon scenario. However, let me try to give you an example with as much relevance as possible.
Imagine having a concrete class: Person
class Person
{
String name; //every person has name
int age; //every person has age
//constructors & other methods not shown
}
And you have an abstract class: Student
The Student class is made abstract with its potential subclass in mind: Part-Time Student
and Full-Time Student
.
abstract class Student
{
String name; //every student has name
int age; //every student has age
int grade; //every student has a current grade (level of studies)
//constructors & other methods not shown
}
Since every Student
is also a Person
with name
and age
, I could possible do this:
abstract class Student extends Person
{
//name & age inherited
int grade;
//constructors & other methods not shown
}
The above is probably not the best class design we can have and it is argumentative that we can rearrange the above classes such that the abstract class is at the top of the hierarchy , but this is just one simple example portraying the idea where abstract class may still inherit properties from a concrete class.
1
solved can i make abstract class a child of normal class in java