+ 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...!!!!
6 Answers
+ 6
Pls use the tag section to specify which language is ur code.
+ 6
Attunuru Baby Sri Laya I was referring to which programming language(like c++,Java etc)
+ 5
Attunuru Baby Sri Laya There's no error in ur code.
Ur code is successfully giving the Output "Hi"..
+ 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.
+ 1
Classes and objects...yeah i used know..!!!
+ 1
Ok...java