In: Computer Science
Assume we have already defined two classes, ClickableShape and Pentagon. Using only the extends functionality of Java, can we create a new class ClickablePentagon?
Answer
No in java we cannot create a new class only using the extends functionality it will occur compiler error becuase java does not support multiple inheritance
example
two classes ClickableShape and Pentagon already exist we try to create a new class ClickablePentagon with the help of extends functionality
for good understanding we will create the following java programe ->
class ClickableShape{
void fun(){
System.out.println("This is ClickableShape property");
}
}
class Pentagon{
void fun(){
System.out.println("This is Pentagon property");
}
}
class ClickablePentagon extends ClickableShape, Pentagon
{
public static void main(String[] args){
ClickablePentagon myClickablePentagon=new ClickablePentagon();
myClickablePentagon.fun();
}
}
this programe will show follwing error due to compiler error
Main.java:13: error: '{' expected
class ClickablePentagon extends ClickableShape, Pentagon
^
1 error
hence we cannot create new class only using extends functionality