+ 1

What is the output of this code?(Java)

public class A { public void test() { System.out.println("Hi"); } } class B { public static void main(String args[ ]) { A obj = new A(); obj.test() ; } } ****For this code i am getting errorđŸ˜„"**** Can anyone please explain...!!!!

2nd Nov 2020, 1:06 PM
Sri Laya
Sri Laya - avatar
6 Answers
+ 6
Pls use the tag section to specify which language is ur code.
2nd Nov 2020, 1:08 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 6
Attunuru Baby Sri Laya I was referring to which programming language(like c++,Java etc)
2nd Nov 2020, 1:11 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 5
Attunuru Baby Sri Laya There's no error in ur code. Ur code is successfully giving the Output "Hi"..
2nd Nov 2020, 1:15 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 4
It might work on sololearn but not on an IDE like eclipse. A .java file can atmost have only 1 public class. Also most importantly the class containing your main method must be public. Try removing public from class A and add it to class B. Considering this a single file, you must name the file as B because the public class name must match the file name.
2nd Nov 2020, 1:22 PM
Avinesh
Avinesh - avatar
+ 1
Classes and objects...yeah i used know..!!!
2nd Nov 2020, 1:10 PM
Sri Laya
Sri Laya - avatar
+ 1
Ok...java
2nd Nov 2020, 1:12 PM
Sri Laya
Sri Laya - avatar