public class Animal
{
public Animal()
{
System.out.println("Animal");
}
}
public class Mammal extends Animal
{
public Mammal()
{
System.out.println("Mammal");
}
}
Is this an object or a class? If not, what would be开发者_StackOverflow中文版 an example of an Object?
These are classes.
new Animal()
would be an object, i.e. an instance of a class.
Both Animal
and Mammal
are classes.
Animal a = new Animal();
The code above will result in a reference, a
, that refers to an object of type Animal
. Since Mammal
extends Animal
, you'd also be allowed to write:
Animal a = new Mammal();
Your reference type would still be Animal
, but this time it's referring to an object of type Mammal
.
The Theory of Forms typically refers to Plato's belief that the material world as it seems to us is not the real world, but only a shadow of the real world. Plato spoke of forms in formulating his solution to the problem of universals. The forms, according to Plato, are roughly speaking archetypes or abstract representations of the many types and properties (that is, of universals) of things we see all around us. Epistemology (From: wikipedia)
To explain it with Plato: The class is a form, 'a shadow'. The 'universals', those many types and properties are the objects.
精彩评论