Skip to main content
Filter by
Sorted by
Tagged with
2783 votes
25 answers
1.1m views

What is the difference between these statements (interface vs type) in TypeScript? interface X { a: number b: string } type X = { a: number b: string };
user avatar
2034 votes
39 answers
1.4m views

What exactly is the difference between an interface and an abstract class?
Sarfraz's user avatar
  • 384k
1579 votes
34 answers
827k views

I have recently had two telephone interviews where I've been asked about the differences between an Interface and an Abstract class. I have explained every aspect of them I could think of, but it ...
Houman's user avatar
  • 66.6k
932 votes
33 answers
236k views

I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this? I know what interfaces do, but the fact I am not clear on this makes me think I am missing ...
Damien's user avatar
  • 14.1k
908 votes
18 answers
648k views

How do I setup a class that represents an interface? Is this just an abstract base class?
Aaron Fischer's user avatar
845 votes
38 answers
208k views

When should I use an interface and when should I use a base class? Should it always be an interface if I don't want to actually define a base implementation of the methods? If I have a Dog and Cat ...
840 votes
19 answers
1.3m views

Please explain in an easy to understand language or a link to some article.
Saad Masood's user avatar
  • 11.5k
739 votes
16 answers
364k views

Does reflection in C# offer a way to determine if some given System.Type type models some interface? public interface IMyInterface {} public class MyType : IMyInterface {} // should yield 'true' ...
Yippie-Ki-Yay's user avatar
722 votes
30 answers
976k views

This question is the direct analogon to Class type check in TypeScript I need to find out at runtime if a variable of type any implements an interface. Here's my code: interface A { member: string;...
lhk's user avatar
  • 30.7k
692 votes
13 answers
175k views

What are the differences in implementing interfaces implicitly and explicitly in C#? When should you use implicit and when should you use explicit? Are there any pros and/or cons to one or the other?...
Seb Nilsson's user avatar
  • 26.5k
652 votes
18 answers
459k views

It's weird that this is the first time I've bumped into this problem, but: How do you define a constructor in a C# interface? Edit Some people wanted an example (it's a free time project, so yes, it'...
Boris Callens's user avatar
650 votes
8 answers
485k views

What is the difference between abstract class and interface in Python?
gizmo's user avatar
  • 8,239
644 votes
16 answers
174k views

Java 8 allows for default implementation of methods in interfaces called Default Methods. I am confused between when would I use that sort of interface default method, instead of an abstract class (...
Narendra Pathai's user avatar
636 votes
15 answers
479k views

(1) List<?> myList = new ArrayList<?>(); (2) ArrayList<?> myList = new ArrayList<?>(); I understand that with (1), implementations of the List interface can be swapped. It ...
kji's user avatar
  • 6,761
576 votes
24 answers
457k views

NOTE: This question predates Java 8. As of Java 8, static methods are allowed in interfaces. However, they cannot be declared abstract (required to be overridden) in the manner requested by this ...
cdmckay's user avatar
  • 32.4k
573 votes
14 answers
373k views

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other?
Scottm's user avatar
  • 7,131
558 votes
26 answers
458k views

This may be a generic OOP question. I wanted to do a generic comparison between an interface and an abstract class on the basis of their usage. When would one want to use an interface and when would ...
Chirantan's user avatar
  • 15.7k
549 votes
31 answers
493k views

In one of my interviews, I have been asked to explain the difference between an Interface and an Abstract class. Here's my response: Methods of a Java interface are implicitly abstract and ...
Thinker's user avatar
  • 6,952
505 votes
15 answers
250k views

Should a method that implements an interface method be annotated with @Override? The javadoc of the Override annotation says: Indicates that a method declaration is intended to override a method ...
Benno Richters's user avatar
456 votes
6 answers
172k views

I haven't touched Java since using JBuilder in the late 90's while at University, so I'm a little out of touch - at any rate I've been working on a small Java project this week, and using Intellij ...
Bittercoder's user avatar
  • 12.2k
445 votes
15 answers
312k views

What is the simplest way of testing if an object implements a given interface in C#? (Answer to this question in Java)
JoshRivers's user avatar
  • 10.3k
435 votes
4 answers
178k views

There are already several Q&As on this "X does not implement Y (... method has a pointer receiver)" thing, but to me, they seems to be talking about different things, and not applying to my ...
xpt's user avatar
  • 23.6k
425 votes
7 answers
156k views

I noticed that with the optional parameters in C# 4 if you specify an optional parameter on an interface you don't have to make that parameter optional on any implementing class: public interface ...
theburningmonk's user avatar
408 votes
18 answers
585k views

I am looking for a way to pass a method by reference. I understand that Java does not pass methods as parameters, however, I would like to get an alternative. I've been told interfaces are the ...
user avatar
401 votes
13 answers
138k views

I've been trying to study up on PHP lately, and I find myself getting hung up on traits. I understand the concept of horizontal code reuse and not wanting to necessarily inherit from an abstract class....
datguywhowanders's user avatar
380 votes
11 answers
148k views

Please explain when I should use a PHP interface and when I should use an abstract class? How I can change my abstract class in to an interface?
user avatar
375 votes
11 answers
268k views

Most OO languages prefix their interface names with a capital I, why does Java not do this? What was the rationale for not following this convention? To demonstrate what I mean, if I wanted to have ...
Allain Lalonde's user avatar
363 votes
7 answers
118k views

Java 8 introduces default methods to provide the ability to extend interfaces without the need to modify existing implementations. I wonder if it's possible to explicitly invoke the default ...
GOTO 0's user avatar
  • 48.8k
349 votes
32 answers
197k views

The reason for interfaces truly eludes me. From what I understand, it is kind of a work around for the non-existent multi-inheritance which doesn't exist in C# (or so I was told). All I see is, you ...
Nebelhom's user avatar
  • 3,951
346 votes
16 answers
508k views

Why are interface variables static and final by default in Java?
Jothi's user avatar
  • 15.2k
327 votes
12 answers
143k views

Should methods in a Java interface be declared with or without the public access modifier? Technically it doesn't matter, of course. A class method that implements an interface is always public. But ...
Benno Richters's user avatar
320 votes
9 answers
280k views

Two interfaces with same method names and signatures. But implemented by a single class then how the compiler will identify the which method is for which interface? Ex: interface A{ int f(); } ...
Jothi's user avatar
  • 15.2k
296 votes
15 answers
211k views

What is an "abstract class" in Java?
user avatar
285 votes
12 answers
236k views

For example, suppose I want an ICar interface and that all implementations will contain the field Year. Does this mean that every implementation has to separately declare Year? Wouldn't it be nicer ...
deltanovember's user avatar
257 votes
13 answers
515k views

Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. For instance I'm able to ...
Martin's user avatar
  • 10.9k
257 votes
7 answers
201k views

I recently watched a Tutorial on Angular 2 with TypeScript, but unsure when to use an Interface and when to use a Model for data structures. Example of interface: export interface IProduct { ...
I_LIKE_FOO's user avatar
  • 2,874
244 votes
15 answers
104k views

Interfaces allow you to create code that defines the methods of classes that implement it. You cannot however add any code to those methods. Abstract classes allow you to do the same thing, along with ...
mk.'s user avatar
  • 26.2k
243 votes
18 answers
182k views

How does one go about and try to find all subclasses of a given class (or all implementors of a given interface) in Java? As of now, I have a method to do this, but I find it quite inefficient (to say ...
Avrom's user avatar
  • 5,057
242 votes
10 answers
85k views

I have just found a static nested interface in our code-base. class Foo { public static interface Bar { /* snip */ } /* snip */ } I have never seen this before. The original ...
Mo.'s user avatar
  • 15.4k
229 votes
8 answers
163k views

I am having some trouble working out how defining constructors in interfaces work. I might be totally misunderstanding something. But I have searched for answers for a good while and I can not find ...
Nypan's user avatar
  • 7,246
220 votes
9 answers
136k views

Consider an example (which compiles in java) public abstract interface Interface { public void interfacing(); public abstract boolean interfacing(boolean really); } Why is it necessary for an ...
Buhake Sindi's user avatar
  • 89.5k
218 votes
11 answers
178k views

Is there a way to get the following function declaration? public bool Foo<T>() where T : interface; ie. where T is an interface type (similar to where T : class, and struct). Currently I've ...
Matthew Scharley's user avatar
213 votes
24 answers
31k views

I'm at a point in my development learning where I feel like I must learn more about interfaces. I frequently read about them but it just seems like I cannot grasp them. I've read examples like: ...
user53885's user avatar
  • 3,829
213 votes
2 answers
139k views

I have this problem which seems a bit weird to me. Take a look at this snippet of code: package coreinterfaces type FilterInterface interface { Filter(s *string) bool } type FieldFilter struct { ...
0rka's user avatar
  • 2,426
213 votes
6 answers
41k views

In Java, it is perfectly legal to define final arguments in interface methods and do not obey that in the implementing class, e.g.: public interface Foo { public void foo(int bar, final int baz); ...
mindas's user avatar
  • 26.8k
211 votes
4 answers
144k views

I have a simple scenario of a login that requires user's input a email and password in Typescript. I need to create some type to get this strong-typed and send it to the back-end. Should this be ...
Josbel Luna's user avatar
  • 2,904
204 votes
8 answers
145k views

Is there some shortcut that would allow me after creating method in an interface, select and jump to implementing class of that interface?
MatBanik's user avatar
  • 26.9k
199 votes
6 answers
148k views

Given a class instance, is it possible to determine if it implements a particular interface? As far as I know, there isn't a built-in function to do this directly. What options do I have (if any)?
Wilco's user avatar
  • 33.4k
199 votes
21 answers
222k views

Java doesn't allow multiple inheritance, but it allows implementing multiple interfaces. Why?
abson's user avatar
  • 9,388
199 votes
8 answers
96k views

One stumbles upon this phrase when reading about design patterns. But I don't understand it, could someone explain this for me?
never_had_a_name's user avatar

1
2 3 4 5
403