3

I would like to know why in Java I can do this

    interface Specification{
    double Interest =12.5;
    void deposit(double);
    }

    class Base{
    private String Account;
    public Base(String acct){Account=acct;}
    public void Show(){System.out.print("Account # "+Account);}
    }

    class Child extends Base implements Specification{
    public Child (String acct){super(acct);Show();}
    public void deposit(double cash){System.out.print("Now you have "+cash+" Dollars");}
    }

but I can't do this

    class Child implements Specification extends Base{
    public Child (String acct){super(acct);Show();}
    public void deposit(double cash){System.out.print("Now you have "+cash+" Dollars");}
    }

Is there any specific order in Java or rule when using extends and implements in the same class. I would like somebody to explain me the reasons please.

P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37

2 Answers2

2

Because the Java Language Specification says so. A normal class declaration follows this syntax

NormalClassDeclaration:
    ClassModifiers(opt) class Identifier TypeParameters(opt)
                                               Super(opt) Interfaces(opt) ClassBody

where Super is

Super:
    extends ClassType

and Interfaces is

Interfaces:
    implements InterfaceTypeList

In my opinion, this makes sense. You want to define what something is before defining what it can do.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
0

Yes in java there is specific order first class in extended then you can implement many classes :

class Child extends Base implements Specification1,Specification2.. -> valid 

&

class Child implements Specification1,Specification2.. extends Base -> not valid 
Kick
  • 4,823
  • 3
  • 22
  • 29