Most voted "polymorphism" questions
It is the feature that allows rewriting methods in the base classes so that a method can behave differently in different classes.
Learn more…70 questions
Sort by count of
-
30
votes1
answer1075
viewsPolymorphism in procedural language
One of the characteristics of object orientation is polymorphism, the ability of a method to perform different behaviors according to the context that can be defined by a hierarchy…
-
17
votes2
answers964
viewsWhy doesn’t polymorphism work with Generics?
When trying to compile the following code I got an error. import java.util.*; class Animal { } class Cachorro extends Animal { } public class TestePoli { public static void main(String[] args) {…
-
17
votes2
answers3267
viewsWhen and why should we use polymorphism?
When and why should we use polymorphism in Java, because so far I’ve only used it to make multiple windows based on a model. The polymorphism the way I’m applying is better than making one window…
-
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,…
-
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
votes1
answer5228
viewsWhat are the differences between overrideing and overloading in Java?
What are the main differences between overrideing and overloading in Java? What is the relationship between these terms and Polymorphism?
-
14
votes2
answers1408
viewsHow and when should we use Interface to document systems in PHP?
I always wondered exactly, if it is a good practice, to make a system always making use of Interfaces, or this is not necessary? Interface People { public function getName(); public function…
-
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
votes1
answer1740
viewsWhat are the differences between the concepts of polymorphism and superscript in OOP?
I was a little confused when researching polymorphism. The concept of polymorphism resembles the concept of superscript. What are the differences between polymorphism and superscript in OOP?
-
12
votes4
answers549
viewsProblem with polymorphism
I have a polymorphism problem. But before I explain it, I want to make it clear that I’m still learning a lot, so if you want to throw my structure in the garbage, be my guest. I have a project that…
-
11
votes2
answers353
viewsIs that a polymorphism?
Is that polymorphism? If so, why? I think it’s because there’s no method call. Please explain to me if I’m correct or correct me. Thank you :) OutputStream saida = new…
-
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
votes2
answers930
viewsPrototype functions in C/C++
What kinds of functions are these? What can these prototypes do? /*1*/int func ( int (*x)(int,int) ) /*2*/int func ( int x(int,int) ) /*3*/int func1 ( int(fn)() ) /*4*/int func2 ( int(*fn)() ) Is…
-
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, 2 months ago Mauricio Ferraz 2,074 -
10
votes2
answers1800
viewsWhat is the relationship between encapsulation and polymorphism?
A few days ago, I was talking to a friend about Java, and asked what part of the story they were studying. Then he replied that they were starting inheritance studies. As they were too late, I asked…
-
8
votes2
answers828
viewsParametric polymorphism and overload in Java and C++
The following question fell in IFSP’s tender procedure: In Java and C++ programming languages, parametric polymorphism is materialized, respectively, by the functionalities and/or characteristics:…
-
7
votes1
answer329
viewsPolymorphism in Java
Example: // Super classe: Carro abstract public class Carro { String nome; public void andar(){ // anda } } // Sub classe: Fusca public class Fusca extends Carro { public void andar(){…
-
7
votes1
answer311
viewsWhen to use Supertype or Subtype when returning the method?
Suppose I have a method called "meuMetodo()" that returns an Object of Type ArrayList<String>, i can make this method declare that returns more concrete or more abstract types: public…
-
6
votes1
answer111
viewsIs it incorrect to change the arguments in an extended class in PHP?
It is incorrect (or "semantically incorrect") to change the arguments in an extended class in PHP? For example I created this class: class Bar { public function __construct($message, $code, $timer)…
-
6
votes2
answers3155
viewsHow does Python overload polymorphism work?
I recently learned POO in Java and am now learning in Python. There is overload polymorphism (implement methods with equal names in the same class, which depending on the parameters you deliver to…
-
5
votes2
answers1174
viewsInstantiating an Object with a different reference
I’m learning polymorphism in Java, but I’m having some doubts. public class Animal { int numPatas; public void fazerBarulho() { // Código do Método } public void comportamento() { // Código do…
-
5
votes1
answer157
viewsIs overlapping polymorphism mandatory?
In overlapping polymorphism is it mandatory that the method of a mother class that will be superimposed on a subclass be abstract? Is there an exception for some POO language?
-
5
votes1
answer509
viewsPolymorphism in Typescript
I am creating my application with the following structure: An abstract class Person, and inheriting from Person, the classes PessoaFisica and PessoaJuridica, And finally, a class Cliente receiving…
-
4
votes2
answers447
viewsHow to adapt / create a method that receives an anonymous class in C#
I have a method in which one of the parameters is an object of an abstract class - Objectmapper - whose purpose is to convert an object of one class into another of another class. Below, the method…
-
4
votes1
answer100
viewsWhat is Monomorphization?
I was reading that posting and I came across that term monomorphization I’d like to know: What is its meaning? When this process occurs? What performance gain/loss is obtained by this process?…
-
4
votes1
answer79
viewsA list of a guy can’t pass as a list of his 'higher' type?
There are some entities in the application that I am developing that need to be sorted by a predefined routine. Thinking about it was created contract class, called ElementoOrdenavel and all…
-
4
votes2
answers540
viewsPHP POO error Polymorphism
When developing a simple PHP POO application, I came across an unexpected error, and I have no idea why. I’m starting now to study object-oriented programming and only have a small C-base#. The…
-
4
votes1
answer1006
viewsOverload method is polymorphism?
I’m having trouble understanding the concept of polymorphism in Java, I read two articles of the same portal now and I was more confused, because for my interpretation they contradict each other:…
-
3
votes1
answer180
viewsGeneric type in Java
I have 3 classes, Expression, Operation, Scalar public abstract class Expression<R extends Expression> { public abstract R calcular(); } public abstract class Operation<T extends…
-
3
votes2
answers238
viewsGeneralization of parameters in Java
I am implementing a B tree for a database job in Java, so that it stores any kind of objects, be generic, so I am treating as if it were Object, but in some parts of precise code methods such as…
-
3
votes3
answers1689
viewsHow to make visual form inheritance in Windows Forms?
I have a form base that will be the form 'Dad, with three buttons on it. Add, Delete and Change. I’m gonna use the formbase to standardize my registration screens, so each registration screen when…
-
3
votes2
answers144
viewsHow to implement polymorphism correctly?
One of the first things we hear about when we study the object-orientation paradigm is polymorphism but how can we or "should" implement it, since it’s a concept we see various forms of…
-
3
votes3
answers823
viewsMethod that returns parent class to daughter class
I have the following classes: public class Pessoa { public int PessoaId { get; set; } public string Nome { get; set; } public DateTime DataNascimento { get; set; } } public class Cliente : Pessoa {…
-
3
votes3
answers77
viewsHow can I access a subclass method through a superclass-like object
Having an ABC super class public class ABC { int x = 0; public int getABC() { return x; } } public class XYZ extends ABC { int y = 0; public int getXYZ() { return y; } } Instantiating an ABC object…
-
3
votes2
answers59
viewsHow to change the way a class/structure is printed?
I have the following structure: struct cores { int r, g, b; public cores(int r, int g, int b) { this.r = r; this.g = g; this.b = b; } } If I had a new structure printed, it would look like this:…
-
3
votes1
answer56
viewsHow to make an interface method receive any object (Object type) as parameter?
I’m studying polymorphism now, and I’m not getting it. Given the interface: public interface View { public boolean existe(Object obj); } I have this method, which I would like to be implemented from…
-
3
votes2
answers174
viewsRequest and Pedidoitem establish a composition?
I took the test of the IFSULDESTE competition of Minas Gerais organized by the CEFET-MG Foundation and I have doubts about the following question: Note the following class diagram. About the…
-
3
votes1
answer116
viewsProblem to use a "System.out" on an object
I’m trying to give a System.out.println on an object I have (even with the toString() in class) I’m getting: Predio [name=LS, aptos=[[Lmodel.Apartamento;@7ba4f24f, [Lmodel.Apartment;@3b9a45b3,…
-
3
votes2
answers164
viewsUpcasting and subsequent downcasting allows you to access the attribute of the original type?
When I make a upcasting, object 1 will be converted to its supertype and an object 2 is created When object 1 is instantiated before doing the upcasting, has attributes that do not exist in the…
-
2
votes0
answers54
viewsError creating a method in a legacy WFA application and polymorphism
I created a WFA project that will serve as a basis for the others, follows the description: I created a Formbase that has public control variables, such as operator name, date and time of access to…
-
2
votes1
answer1104
viewsTake and display data from a class attribute (class association)
I’m having a little trouble picking up a value from an attribute of the type class. Classe Pessoa public class Pessoa { public string Nome {get;set;} public int Idade {get;set;} public virtual void…
-
2
votes3
answers121
viewsInteresting question about inheritance and polymorphism
I found this question of an open competition interesting: Class A public class ClasseA { public int metodoX(){ return 10 } public int metodoX(int n){ return metodoX() + n } } Class B public class…
-
2
votes2
answers135
viewsDoubt about access modifiers and polymorphism
I have a very beginner question about polymorphism/access modifiers in Java. I’d like to find out why a certain phenomenon occurs in my code. Below is an example of classes: Class Pai: public class…
-
2
votes3
answers209
viewsPolymorphically manipulating subsclasses
How Superclass Manipulation of Subclasses Works? In this code, the array of one class, prints the values of other classes. zoo java. public class zoo { public static void main(String[] args) { Vaca…
-
2
votes1
answer64
viewsHow to assemble a collection of derived objects, and use specific functions of each?
I want to create a dynamic list that contains all Component derived objects. I’m trying to do it this way: map<string, Componente> tabuleiro_componentes;…
-
2
votes2
answers259
viewsInvoke child class method in C++
I have a parent class/structure and a daughter class/structure in C++. The parent class defines a method, and the daughter class burdens that method. Trivial example: struct Pai { void imprimir() {…
-
1
votes1
answer163
viewsUsing Connection is polymorphism?
Connection connection; connection = new ConnectionFactory().getConnection(); I can say that doing this is polymorphism? The Connection receive the class connection ConnectionFactory.…
-
1
votes3
answers871
viewsPolymorphism in C
It is possible to use Polymorphism in a structured language such as C? Languages such as c++,Java,etc(Object-oriented languages), have structures capable of inheriting functionalities for code reuse…
-
1
votes1
answer182
viewsOverwrite static method
I don’t even know how to ask the question, but I’ll try. I have a static method in a parent class, and I planned to overwrite in the child classes, but from what I’m seeing here, this is not…
-
1
votes3
answers347
viewsForm Inheritance created in Runtime
Follow the code below: type TfObject = class(TForm) private procedure FormShow(Sender : TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure…