I have studied C++ and now I'm studying Java. In C++ we can use static members in non-static/instance member functions. But while studying Java I found this :
I wrote a program to check if " the non-static function can access static member or not". And there was no problem in the program below :
public class Animal
{
static int CountOfAnimal;
public Animal()
{
CountOfAnimal++;
}
public int showCount()
{
CountOfAnimal++;
return CountOfAnimal;
}
public static void main(String []args)
{
new Animal();
new Animal();
Animal C = new Animal();
System.out.println("Total animals are : " + C.showCount());
}
}
So, can I say that in Java also the non-static/instance member functions can access static members of same class?
Also, I want to know if there is any difference between static members(methods and variables) in Java and C++ other than the way of calling the members?
One difference I know is in the way of calling the static members in C++ and calling static members in Java. Any other?
