In PHP, to create a new object you would do something like this, $dog = new Dog;. But in Java you would do something like, Dog x = new Dog; or Dog x;. Could someone explain why you need to say the Dog class in front of the variable?
In PHP, to create a new object you would do something like this, $dog
Share
Java statically and explicitly typed.
The type of the variable may be different from the type of the value it holds, due to inheritance. For example:
Here the type of the
dogvariable isAnimal, but the value it holds is a reference to an instance ofDog.Now in some other languages (C# 3 being the obvious example as a near neighbour of Java) you can use implicitly typed local variables when you actually want the type of a local variable to be the same as the type of the expression used to initialize it:
(The type inferencing capabilities of some other statically typed languages go well beyond this.)
So, to go back to your original question, the answer is:
dogvariable has a type which is known at compile-time; this isn’t true in PHP