T
T
thatmaniscool2017-05-09 21:04:42
Java
thatmaniscool, 2017-05-09 21:04:42

Multiple inheritance java, what am I doing wrong?

First of all, I create a "top class".

public class TOP {
  public TOP() {
    System.out.println ("TOP");
  }
}

It has two branches, left and right.
public class LEFT {
  public LEFT (){
    super ();
    System.out.println("LEFT");
  }
}

and
public class RIGHT {
  public RIGHT (){
    super ();
    System.out.println("RIGHT");
  }
}

Next, it looks for a common class that inherits the elements of the left and right classes.
public class CommonClass extends RIGHT, LEFT {
  
  public static void main (String [] ags){
    new RIGHT ();
    new LEFT ();
  }
}

Gives the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "]", :: expected after this token
Syntax error, insert "SimpleName" to complete Type
at CommonClass.main(CommonClass.java:4 )

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladislav, 2017-05-09
@Div100

Multiple inheritance java, what am I doing wrong?

What's wrong?
You can only inherit 1 class.
But you can implement up to a bunch of interfaces
//A-Z  - интерфейсы
public class CommonClass extends Direction implements A, B, C, D, Z

A
Alexander, 2017-05-11
@kick_fuel

It is possible to inherit only 1 class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question