11

I came across this question where the OP is asking for some inheritance concept. Here is the overview:

One.java

public class One {

  private void run() {
      System.out.println("one");
  }

  public void start() {
      this.run();
  }
}

Two.java

public class Two extends One {
  public void run() {
      System.out.println("two");
  }
}

Main.java

public class Main {
  public static void main(String[] args) {
      Two t = new Two();
      t.start();
  }
}

Output: one

But if I declare public the run method in One class I get: two.

One of user answered it and the OP accepted it. Part of the answer:

The run method in Two will not be overriding the private method in One, because it is private and inaccessible to any class outside One.

But I had some doubts about that. t contains object of Two but Two does not contain start() so it it uses One's start method which has a body this.run(). Here this is current calling object Two's object it's like new Two().run() so why didn't it display two rather than one?

The above problem are my doubts. I already tried to resolve my doubts by posting a comment but the answerer didn't reply. So what should I do in this case? Should I create a new question or not? I want to clear up my confusion about this, but I don't want to create duplicate question.

8
  • 4
    Looks like the answerer replied to you. In general, give an answerer some time; they may have other things they need to address before they get a chance to reply here again.
    – Makoto
    Commented Oct 16, 2015 at 16:15
  • @Makoto It was not actually the answerer but you are correct I cant force someone to reply to my comment anyway thanks for the help
    – codegasmer
    Commented Oct 16, 2015 at 16:40
  • 9
    You should probably read some books to learn the basics.
    – user1228
    Commented Oct 16, 2015 at 16:42
  • @Will I tried though but I keeps on forgetting the concepts again and again I am so frustrated with myself
    – codegasmer
    Commented Oct 16, 2015 at 16:48
  • 20
    @codegasmer If you're forgetting things then you should be looking them up again, not asking people to look it up for you because you can't be bothered to look it up again.
    – Servy
    Commented Oct 16, 2015 at 17:48
  • 1
    @Servy my SO experience say that you have to research before asking thats what I did and I cant find anything I know there would be some source some I found which dint clear my doubts and some I dint found so I asked the answerer to help me clear my doubts. If the case you are saying research research and research exits then the SO would never exist.
    – codegasmer
    Commented Oct 17, 2015 at 5:43
  • 7
    @codegasmer 1. You apparently had no trouble finding information on it before, you just said you kept forgetting the concepts, why could you find it earlier and not now? 2. There's tons of information on this topic, all over the place. There's simply no way that you could say that you can't find information on this topic. SO is here to create content for people to find in their research, not to repeat widely accessible information for people who can't be bothered to search Google to get an answer. It's been SO's mission from day 1.
    – Servy
    Commented Oct 17, 2015 at 17:04
  • 10
    Sorry. If you keeps on forgetting the concepts again and again, someone else explaining them again isn't going to help. Dig out your books, and read and study the material as many times as you need to until you have them memorized well enough you won't forget them again.
    – Ken White
    Commented Oct 17, 2015 at 20:51

1 Answer 1

14

Should I ask a new question if I have doubts/confusion about the answer?

The General Case

The answer in the general case is maybe, but that's not the first thing you should do. Neither is posting a comment to the answerer.

The first thing you should do is look for an answer to your question — in the standard reference material, in tutorials, in books on the subject, on Stack Overflow, elsewhere on the 'net, etc.

If and only if you've looked hard and not found relevant explanations that you could understand, then you might consider posting a question saying what you don't understand and outlining what you've read about it, and specifically what it is about the explanations you've read that you still don't understand.

This Specific Case

No, you shouldn't. Any basic tutorial on Java inheritance will explain why you can call start on t, usually with diagrams and in detail. There are hundreds if not thousands if not hundreds of thousands of Java inheritance tutorials. Work through as many of them as you need to until you understand it. If you get through several of them and still don't understand it, then you are clearly not going to understand it from a written source, you'll need to look for someone who can mentor you one-on-one. A question about it on SO is not going to help, and SO is already well-stocked with Java inheritance questions.

2
  • 2
    I really like your answer - the way you separated it. Other than what the OP is asking about regarding the Java question, the question itself is absolutely valid. Unfortunately folks in the comments section submitted themselves to judging the content first. +1 and cheers!
    – Michal
    Commented Oct 19, 2015 at 8:31
  • 1
    The If and only if is best part and thats what my aim was for asking a question.
    – codegasmer
    Commented Oct 19, 2015 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .