I understand that when creating a new object such as this:
GeomObject tri = new Triangle();
is more general and allows for more resuability, but what happens when tri is created like this:
Triangle tri = new Triangle();
Since Triangle is a subclass of GeomObject, isn't tri still a GeomObject? How does the declared type affect compilation? Thanks
*add: An additional question: say I have
Integer n1 = new Integer(3);
Object n2 = new Integer(4);
System.out.println(n1.compareTo(n2));
I tried this out on Eclipse and I got errors even if I reversed n1 with n2. I thought that n2.compareTo(n1) would work because it would call the Object compareTo method and since Integer is an instance of object, it would be passable, but this is not the case. Could you explain this?