+ 2

Can i extend inheritance class after main method or does it have to be before?

example class{ main{ extended class{ }}}

11th Sep 2017, 1:24 PM
D_Stark
D_Stark - avatar
5 Antworten
+ 6
The extends keyword an only be used at the class declaration after the class name (or after the interface's name, if there are any implemented). So you can't use it inside a method. But you could use it inside a class at the declaration line of a nested inner class.
11th Sep 2017, 2:02 PM
Tashi N
Tashi N - avatar
+ 6
You can't have two main methods in one file. The JVM doesn't know where to start from then.
11th Sep 2017, 2:11 PM
Tashi N
Tashi N - avatar
+ 6
Well... yes. If that's what you want to do. But why did write the other main method then? It's unused ;)
11th Sep 2017, 2:25 PM
Tashi N
Tashi N - avatar
+ 1
ah right i think i understand, this is what i was working on anyways. . https://code.sololearn.com/czyYxO2P1lIB/?ref=app
11th Sep 2017, 2:10 PM
D_Stark
D_Stark - avatar
0
it still works which i find odd lol. so all i need to do is move my 2nd program above first main right?
11th Sep 2017, 2:18 PM
D_Stark
D_Stark - avatar