Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
40 views
asked by Expert (15k points) 15 23 32

1 Answer

0 votes
Within a subclass you can access its superclass's public and protected methods and fields , but not the superclass's private methods. If the subclass and the superclass are in the same package, you can also access the superclass's default methods and fields.

public class P {
  public void publicMethod() {
  }

  protected void protectedMethod() {
  }

  void defaultMethod() {
  }
}

class C extends P {
  public void testMethod() {
    publicMethod();
    protectedMethod();
    defaultMethod();
  }
}
answered by Geek (15.3k points) 19 43 70

Related questions

0 votes
1 answer 26 views
26 views asked by felin Advisor (8.4k points) 10 15 18
0 votes
1 answer 58 views
58 views asked by rock Expert (15k points) 15 23 32
0 votes
1 answer 34 views
34 views asked by smith Geek (15.3k points) 19 43 70
0 votes
1 answer 25 views
25 views asked by augustaina Sr Member (4.8k points) 10 26 32
0 votes
1 answer 17 views
17 views asked by john Guru (27.1k points) 35 53 115
...