1

How do I implement two interfaces in a class like so:

public class MainActivity extends Activity implements RewardedVideoAdListener implements GoogleApiClient.ConnectionCallbacks {
}

If it's impossible, what's the simplest workaround?

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
Jonathan Doe
  • 101
  • 5
  • 20
  • 1
    @randnum-1 It is possible with interfaces. – shmosel Jul 14 '17 at 21:16
  • It is possible. Stop misguiding him :@ – Nouman Ghaffar Jul 14 '17 at 21:21
  • @randnum-1 who is asking about multiple inheritance? – Nouman Ghaffar Jul 14 '17 at 21:25
  • Consider whether implementing two interfaces is the right thing here anyway: *is* `MainActivity` a `RewardedVideoAdListener`, or does it merely *have* a `RewardedVideoAdListener`? You could just create inner classes for the two types of listener. [See this question](https://stackoverflow.com/questions/17540013/declaring-that-a-class-implements-onclicklistener-vs-declaring-it-yourself). – Andy Turner Jul 14 '17 at 21:30
  • @AndyTurner Understood. Please give an answer with examples. – Jonathan Doe Jul 14 '17 at 21:32

2 Answers2

5

Simple

public class MainActivity extends Activity implements RewardedVideoAdListener ,GoogleApiClient.ConnectionCallbacks {
}

Use a comma instead of implements.

Nouman Ghaffar
  • 3,780
  • 1
  • 29
  • 37
3

Yes, you can just separate the classes it implements with commas rather than multiple implements keywords

public class MainActivity extends Activity 
   implements RewardedVideoAdListener, ConnectionCallbacks { }
Eddie Martinez
  • 13,582
  • 13
  • 81
  • 106