H
H
have_a_questions2016-03-11 19:00:36
OOP
have_a_questions, 2016-03-11 19:00:36

Why can't I access methods through a class?

there is a class A which has private field getters, for example public int getX() {retutn this.x} . When I access the getX() method from class B through class A, that is, A.getX(), then an error occurs, and when I declare a class variable of type A a, the compiler already sees the method through a.getX().
1. Please explain what is the joke here.
2. Declaration of variables like object can be stored on the heap before initialization?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maaGames, 2016-03-11
@have_a_questions

Only static methods can be called through the class name.

V
Viktor, 2016-03-11
@master2016

Who knows. It can be assumed that you are accessing a method without creating an object. And how does he know in this case - what is this.x?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question