-3

this person has done:"protected GoogleApiClient mGoogleApiClient;" in the following code :

Android Maps Get Longitude and Latitude

but GoogleApiClient is an abstract class.

How it's instance can be created ?

Abstract class as mentioned here: https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient

Should'nt it be extended as abstract classes can only be extended?

2
  • An abstract class cannot be instantiated directly. The user is not attempting to do that so there is no problem.
    – Kuffs
    Jan 18, 2016 at 13:01
  • The statement in this message is not correct.
    – DanielV
    Jan 18, 2016 at 13:27

1 Answer 1

2

It is not instantiated directly. If you look at the code in the link you provide, this is how an instance of a subclass of GoogleApiClient is produced :

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

We don't use the new keyword here, but rather the build method from the static class Builder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.