Does the following code will compile if both classes are declared in Test.java?

//Test.java
public class Car{
    public String myCar = "Ferrari" ;
}
public class Test{
    public static void main(String ... args){
        Car myCar = new Car();
        System.out.println(myCar.myCar);
    }
}
Explanation
Code will not compile because of the class Car. Only one of the classes in the file can be declared as public.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes