sometimes we can from ClassA do :
import com.software.ClassB;
classbObject = new ClassB ;
ClassB.getMethodX();
and we can also from ClassA make directly
import com.software.ClassB;
classbObject = new ClassB ;
classbObject.getMethodX();
what is the diffrence between these 2 cases (calling directly the class or the object)? is there one recommended?
thanks,
You mean why this :
is different from this?
If so, then the second is somehow wrong. I mean it still works, but it makes no sense. The method is declared as static, which “belongs” to the class. You have one static method for a class, not matter how many instances. So, every static method should be called in a static way:
ClassB.getMethodX()