same name defined for method and object?
public class MyClass { public static void main(String[] args) { Car Car1 = new Car(); // to be removed System.out.println(Car1.Brand); } } class Car1 { static String Brand = âToyotaâ; } // class to be removed class Car() { String Brand = âAudiâ; } === Now I have learnt a few types of entity (or âthingâ? I donât know how to call themâŠ), namely object, class, method and variable/attribute. If I give the same type of âthingâ the same name, it looks like Eclipse will warn me about this (like, when I created two classes named âCarâ, an error message will be shown. I did not test other types of âthingsâ though). I then suspected what would happen if I name different types of things the same name. In the above example, I name a class Car1 (attaching a static label âToyotaâ), but at the same time, name an object Car1 (attaching a label âAudiâ) as well, which was created from another class Car(). When I print the label, âAudiâ poped up and it looks like âToyotaâ was overidden. To make sure I did not write the syntax wrong, I deleted the parts indicated above and re-ran the program, and âToyotaâ poped up. So my questions are: 1. Why does the object takes over the class when calling the expression âCar1.Brandâ? In what order does java consider in this situation? 2. Why wasnât any warning shown for this?