Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use implements and extends at the same time?

Tags:

java

android

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?

like image 331
Jeyjey Avatar asked Jul 11 '16 09:07

Jeyjey


People also ask

Can I extend and implement in Java?

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.

Should implements or extends first?

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.

Can you extend and implement an interface?

An interface can extend any number of interfaces. An interface can never implement any other interface.

Can we use implements and extends together in typescript?

Yes you can do that.


2 Answers

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.

like image 57
Bathsheba Avatar answered Oct 19 '22 07:10

Bathsheba


You can only extend one class but you implements multiple interfaces as your need.

like image 14
Sohail Zahid Avatar answered Oct 19 '22 09:10

Sohail Zahid