In java the interface should have same name as file name, at the same time my main class also should have same name as file name | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

In java the interface should have same name as file name, at the same time my main class also should have same name as file name

Iam getting error, as "it's already defined". But I can't give different name also, what should I do, can anybody help.

2nd Aug 2019, 6:42 PM
Govindaraju C
Govindaraju C - avatar
5 Answers
+ 2
~ swim ~ thank you, I'll try
3rd Aug 2019, 11:43 AM
Govindaraju C
Govindaraju C - avatar
+ 1
What does it say that is already defined? A variable name? A class name?
3rd Aug 2019, 1:35 AM
Sonic
Sonic - avatar
0
public interface GenDemo{ void add() ; } class imp implements GenDemo{ public void add() { System.out.println("addition of two numbers"); } } public class GenDemo { public static void main(String args[]) { imp a=new imp(); a.add(); } }
3rd Aug 2019, 11:27 AM
Govindaraju C
Govindaraju C - avatar
0
Just above the main , it showing "the type GenDemo is already defined"
3rd Aug 2019, 11:29 AM
Govindaraju C
Govindaraju C - avatar
0
Sonic yaa at class name not in interface. If I give different name to interface it shows " interface should define in its own file"
3rd Aug 2019, 11:30 AM
Govindaraju C
Govindaraju C - avatar