Most voted "inheritance" questions
In object-oriented programming, inheritance is the system that allows objects to support operations defined by previous types without having to provide their own definition. She is the main vector for polymorphism.
Learn more…245 questions
Sort by count of
-
71
votes2
answers4053
viewsIs it wrong to use class inheritance to group common behaviors and attributes?
What they teach us about Inheritance The overwhelming majority* of materials dealing with Class Inheritance exemplify it as a mere mechanism for grouping common attributes or actions. At most, as a…
-
66
votes3
answers2309
viewsIs it right to prefer composition to inheritance?
I’ve read several articles and books of Designer Patterns the expression Prefira composição em vez de herança. I believe it is a rather controversial subject due to the views discussed. In my view,…
-
30
votes2
answers4104
viewsWhen should I use Inheritance, Abstract Class, Interface, or a Trait?
From PHP 5.4 we have the Trait, that "are mechanisms that help (and greatly) the reuse of code, and serve perfectly to solve the problem of lack of multiple inheritance". Example of Abastrata Class…
php interface inheritance abstract-classes traitasked 9 years, 5 months ago Wallace Maxters 102,340 -
27
votes3
answers1011
views@Override is required in Java?
If I have an abstract class Pessoa with an abstract method lerNome when I’m implementing this method in my class João I must make use of @Override in lerNome? The same happens when I use interfaces?…
-
27
votes4
answers1698
viewsWhy use C#extension methods?
What I get with extension methods I don’t earn with inheritance? Simply using it as the same name is complicated, since it creates more confusion than anything else.
-
24
votes1
answer2920
viewsIs this a correct example of Javascript inheritance?
I am studying ways to apply Object Orientation in Javascript. I found a solution to utilize inheritance. I wonder if there are better ways and how to encapsulate my classes. What I’ve been doing:…
-
23
votes1
answer15547
viewsHow is 'super' used in Python classes and what is it used for?
How to use and for what purpose super in classes Python?
-
23
votes2
answers2433
viewsWhat is Javascript Prototype?
I see in various instances of native objects a '.protoype' in the middle before a method or attribute but I don’t know what they are EXACTLY. The only thing I know is that it’s Javascript’s way of…
-
21
votes2
answers15418
viewsDoesn’t Java have multiple inheritance?
I had seen somewhere now I don’t remember, I think it was in a course on object orientation, which Ruby possesses. But in Java I’ve never seen it. Is that why abstract classes are used? Or is this…
-
19
votes3
answers12047
viewsWhy doesn’t C# allow multiple inheritances?
In C# we can implement several interfaces. However, because we cannot inherit from more than one base class?
-
17
votes1
answer191
viewsDoubt of competition on inheritance and polymorphism in object orientation
I took the test of the IFNMG competition for the position of computer teacher. The bank that prepared the test was the CEFET Foundation. One of the questions was this:: About the statements below,…
-
16
votes2
answers3148
viewsWhy does everyone hate multiple inheritance in C++ and what’s your difference to mixins?
I’ve always heard that multiple inheritance in C++ is chaos. Why? It wouldn’t be technically the same thing as using mixins in languages such as Ruby? And what is this abstract class of Java? It’s a…
-
15
votes3
answers590
viewsDoubt about Inheritance
I have the following case: Avo.: public class Avo { public String quemEuSou(){ return this.getClass().getName(); } } Mae.java: public class Mae extends Avo{ @Override public String quemEuSou() {…
-
14
votes6
answers1655
viewsHeritage and Polymorphism
I have the class Funcionario. private String nome; private int idade; public function vender (Funcionario f) { ... } I have the subclasses Gerente and Professor that inherit (extend) from…
-
13
votes1
answer8955
viewsInheritance in relational database
one of the great challenges in developing object-oriented software is to abstract the data from its base to power-like objects better manipulate them, today the available ORM frameworks make this…
database oop modeling pattern-design inheritanceasked 10 years, 2 months ago Tuyoshi Vinicius 4,046 -
13
votes1
answer87
viewsHow does the compiler know the difference between the type I’m using in downcasting?
The classes Felino and Ave inherit from Criatura, the values are hypothetical only to inform the difference between specialized attributes. Criatura c1 = new Felino("Preto", true); Criatura c2 = new…
-
12
votes2
answers5287
viewsHow to implement the Repository Standard in C# with EF?
I want to make an implementation of the standard Repository where I will be using the Entityframework and have the following: Interface IRepository: public interface IRepository<T> where T :…
-
12
votes2
answers13989
viewsWhat is the function of the super in a Java constructor?
I have a daughter class that inherits from another abstract class, and in the class builder I have the following: Public aluno(String nome, int idade){ super(nome,idade); } What is the function of…
-
12
votes3
answers637
viewsIs it correct to state which interface solves the multiple inheritance problem in Java?
It is known that Java does not support multiple heritages. Is it correct to say that the interface concept solves the multiple inheritance problem in Java? If so, why?
-
12
votes1
answer479
viewsIs inheritance a bad practice for all languages?
I took a course in architecture of Java projects and the instructor told me that heritage in Java is considered a bad practice, which should always be avoided and is preferable if possible to use…
oop software-engineering encoding-style inheritanceasked 7 years, 12 months ago Fernando Bittencourt 174 -
10
votes2
answers163
viewsWhat is differential inheritance?
I was reading this article in the English OS and came across the term Differential inheritance. Which, exactly, is differential inheritance? It is possible to have a minimum example, preferably in…
-
10
votes1
answer3650
viewsWhat is the difference between virtual and Abstract methods?
In which cases should I prefer to use one type instead of the other?
-
10
votes1
answer1490
viewsPolymorphism or inheritance?
I’m learning about polymorphism and I’ve been wondering if what I’m doing is actually polymorphism or just inheritance? If it’s polymorphism what’s in my code that I can clearly identify is…
c# oop software-engineering inheritance polymorphismasked 8 years, 3 months ago Mauricio Ferraz 2,074 -
10
votes3
answers341
viewsWhy am I calling the subclass method?
public class A { public String imprimir() { return "A"; } } public class B extends A { public String imprimir() { return "B"; } } public class C extends B { public String imprimir() { return "C"; }…
-
9
votes1
answer21547
viewsHow can one CSS style class inherit from another class?
I have a class circulo with various properties: source and shape, etc and I have another class circulo1 with the property size and color. I have to make several circles of different sizes with the…
-
9
votes2
answers245
viewsConfused about the correct form of Inheritance in Javascript
I am studying ways to apply Object Orientation in Javascript. I realized that there are several ways to do Inheritance in Javascript. I did the one that I thought was simple and worked. But is it…
-
9
votes1
answer568
viewsHow does inheritance work in Postgresql?
How does inheritance work in Postgresql? Is it a good practice in relational databases? How to use it?
-
9
votes2
answers450
viewsStatic blocks, heritage and constructors in Java
Hello, during my studies in Java I came across the following question Given the code below: class Foo extends Goo { static { System.out.println("1"); } { System.out.println("2"); } public Foo() {…
-
9
votes3
answers170
viewsHow to change property access level in an inheritance?
I have a class that when inherited I want one of its public attributes to become private, so that the user does not have access to the use of this variable in this class, but I do not know how to do…
-
8
votes4
answers688
viewsSuperclass can become subclass?
I have the classes Versao, that a general version, VersaoFirmware and VersaoSoftware. In practice the user can add one or more versions to an equipment. However, at first, it is not yet known what…
-
8
votes2
answers2209
viewsHow to Extend/Inherit Angular2 Component?
Doubt I would like to create extensions for some components already implemented in Angular 2, without having to rewrite them almost completely, because the base component could undergo changes and I…
-
7
votes1
answer79
viewsWhy can’t a Trait implement an interface?
Why a Trait cannot implement an interface in PHP?
-
7
votes2
answers820
viewsWhat is type and state inheritance?
Recently in a Java simulation, I came across a question related to inheritance classification, which I had never seen before. Taking the opportunity, I will separate into topics, so that the answer…
-
7
votes1
answer140
viewsIs the purpose of the inheritance reuse?
Many say that the goal of object-oriented inheritance is to promote code reuse, but I believe this is a mistake. I remember (or think) reading that the goal is NOT reuse but I don’t remember now…
-
6
votes2
answers375
viewsDoubt with inheritance in Java method
I have the interface below public interface BaseRelatorioDTO extends Serializable { public BaseFiltroDTO getFiltro(); public List<? extends BaseRespostasDTO> getRespostas(); } And I’d like to…
-
6
votes2
answers1395
viewsDoubt in inheritance exercise in C#
I’m trying to solve an inheritance exercise and I found a question that I saw that you have a chance to show up in other places and so I thought I should ask here. The exercise asked to first create…
-
6
votes3
answers1383
viewsLegacy of screens - Android
Wanted to create a screen(Activity) base for the android app I’m developing, so that all other screens inherited from this base. Thus, the screen would have an area reserved for the top of the page,…
-
6
votes2
answers6436
viewsClass, Superclass and Subclass
Regarding inheritance by code reuse in C# I have the following doubt: What’s the difference between classes, superclasses and subclasses? This changes something when doing code reuse? Additional…
-
6
votes2
answers614
viewsInterface and inheritance for the Java connection class
Considering the object orientation, would the use of inheritance and interface in this way be correct? But in this way, any request for connection to the database will need a new object. Would have…
-
6
votes2
answers140
viewsHow do I access getters and sub-class setters?
In this application we have the class Automóvel: public class Automovel { private String marca; private String matricula; private String anoConstrucao; private Motor motor; private int preco = 0;…
-
5
votes0
answers75
viewsWhy should we prefer composition over inheritance?
Since the popularization of object orientation in the 90’s I hear that composition should be preferred before creating hierarchy of types. But perhaps the most important concept of object…
oop inheritance software-engineering composition liskov-principleasked 10 years, 6 months ago Maniero 444,682 -
5
votes1
answer340
viewsWhat is the correct way to declare a chain of methods and prevent the same method from being used outside the scope?
In my last questions I was creating some methods to automate some queries. It’s legal, but now I need to control access to methods by specifying a sequence. When using the method Select(), i cannot…
-
5
votes2
answers117
viewsInheritance or Addiction?
Well, my question is this. I’m refactoring a system where I have an integration with a REST API, there’s a class called Marketplace (That queries the API) that I currently extend from the class Curl…
-
5
votes1
answer143
viewsTraits don’t take property superscripts?
According to the excerpt from the PHP Handbook A Trait is intended to reduce some simple inheritance limitations by allowing a developer to reuse sets of methods freely... Take an example: trait…
-
5
votes2
answers103
viewsDoubt in inheritance
I have a question about inheritance. I have the following code: public class CovariantTest { public A getObject(){ return new A(); } public static void main(String[] args){ CovariantTest c1 = new…
-
5
votes1
answer1351
viewsMultiple inheritance and diamond problem
What’s wrong with the diamond? How do languages treat it? And they treat themselves differently because there is this difference?
-
5
votes2
answers1026
viewsCan a subclass have two superclasses?
Suppose I have a superclass Pessoa and another Funcionário, with its certain attributes and methods. My class Professor may be "daughter" of Pessoa and Funcionário, once it fits both? If yes how is…
-
5
votes2
answers2096
viewsMysql and C#inheritance modeling
I have a question about modeling a Desktopapplication system in C# with Mysql. Essentially I will have the entities Customer, Supplier, PF and PJ. PF can be a customer or supplier. And PJ can also…
-
5
votes1
answer122
viewsInheritance at compilation time?
I was reviewing some codes and some concepts when I find the following assertive: The legacy mechanism in Java occurs at compile time, i.e., every reuse of code accomplished by inheritance is…
-
5
votes2
answers134
viewsWhen do I need to use a class that inherits from an Arraylist of a kind? I don’t understand what that’s for
Example: public class ListaAdapterItem extends ArrayList<Item>{ } And I got a class Item: public class Item { private int imagem; private String nome; private String descricao; public Item(int…