Can i use the implements and the extends at the same time? Because I need to inherit something on the other class while i used implements on the same class.
public class DetailActivity extends AppCompatActivity
implementsView.OnClickListener "extends ListActivity"
How can it be like that?
The extends keyword is mainly used to extend a class i.e. to create a subclass in Java, while the implements keyword is used to implement an interface in Java. The extends keyword can also be used by an interface for extending another interface.
The extends always precedes the implements keyword in any Java class declaration. When the Java compiler compiles a class into bytecode, it must first look to a parent class because the underlying implementation of classes is to point to the bytecode of the parent class - which holds the relevant methods and fields.
An interface can extend any number of interfaces. An interface can never implement any other interface.
Yes you can do that.
Yes, you can. But you need to declare extends
before implements
:
public class DetailActivity extends AppCompatActivity implements Interface1, Interface2 {
// ...
}
Any number of interfaces can be implemented, if more than one then each needs to be separated with a comma.
You can only extend one class but you implements multiple interfaces as your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With