user2873613
user2873613

Reputation: 21

How to access public method present inside private class

My Code:

public class location
{

private class MyPhoneStateListener extends PhoneStateListener
    {
       //Get the Signal strength from the provider, each time there is an update 
      @Override
      public void onSignalStrengthsChanged(SignalStrength signalStrength)
      {

      }
/*some text*/

}

how can i invoke "onSignalStrengthsChanged" method from "location" class.

Upvotes: 1

Views: 139

Answers (1)

Avi
Avi

Reputation: 21858

You need to create a new MyPhoneStateListener instance and invoke the method on this instance.

For example:

public class location {

    private class MyPhoneStateListener extends PhoneStateListener {
      //Get the Signal strength from the provider, each time there is an update 
      @Override
      public void onSignalStrengthsChanged(SignalStrength signalStrength)
      {

      }
      /*some text*/

    }

    public void doSomething() {
        PhoneStateListener listener = new MyPhoneStateListener();
        listener.onSignalStrenghtsChanged(...);
    }
}

Please notice that you can only create a MyPhoneStateListener instance in the location class because you defined the class private.

Also, notice that doSomething() belongs to location.

Upvotes: 4

Related Questions