Most voted "method" questions
A class method is nothing more than a collection of instructions grouped together for the purpose of executing a given task.
Learn more…271 questions
Sort by count of
-
3
votes1
answer6899
viewsPython: How to correctly import one method that depends on another?
I’m on the reboot of a project I did in Java, seeking to learn about Python in POO, but I’m stuck on something I haven’t found any solution yet: I have 2 files ("working.py" and ".py files"). The…
-
3
votes2
answers224
viewsIs it possible to force a method to be called only by a specific one?
I have a father method that calls a son method, I wish the son method could only be called exclusively by the father method, it would be possible? Example: public void MetodoPai(){ //codigo…
-
3
votes2
answers118
viewsWhat is the difference between getRating() and getProgress()?
According to the documentation getProgress returns the level of progress of the rating bar, while getRating returns the number of stars of the rating bar. So in general terms getProgress returns a…
-
3
votes2
answers106
viewsHow do I get a variable in another method?
I declared a variable within the class Main and I want to use it within a method, as I put it there? public class Main { static Scanner entrada = new Scanner(System.in); Aluno aluno = new Aluno();…
-
3
votes2
answers88
viewsI cannot invoke a Setter or getter in Javascript
I was doing some object orientation exercises and in the solution the teacher used set and get. I realized that even if I do it like the teacher, it doesn’t work. I can solve it without get and set,…
-
3
votes1
answer56
viewsDefining the chained methods of a method
Let’s say I have the following class: class animal{ private $animal; private $som; function gato(){ $this->animal = 'gato'; return $this; } function cachorro(){ $this->animal = 'cachorro';…
-
3
votes1
answer549
viewsCS7036 error on C# calling a function
I just got into the matter of functions and methods and I’ve come across a problem that I can’t solve at all because I don’t understand why. The point is: "Create a method that takes an integer…
-
2
votes1
answer130
viewsWhen using recursion method returns 0
I have the following code: public int lerInt() { String entrada = ""; int saida = 0; try { entrada = input.readLine(); } catch (IOException e) { System.out.println("Falha critica."); } try { saida =…
-
2
votes2
answers2470
viewsMethod with generic return
How do I make a method that returns a type informed in the parameters? public <E> E to(E e) { return (E)obj; } String st = to(String); Integer it = to(Integer); But it creates error, there’s…
-
2
votes1
answer1471
viewsCalling another class method in the same application
I’m having a great difficulty to perform a task maybe even simple, for those who are more used to the Java language on Android. I have an application that has menus with options. One of them is to…
-
2
votes1
answer6363
views -
2
votes1
answer159
viewsOutput of a method or event - C# / WPF
I am using a return to be able to leave the event textEstado_Validate. The problem is that when he leaves this event, he enters the textEstado_KeyDown. How can I make sure he doesn’t enter any other…
-
2
votes1
answer62
viewsValidate method name by suggesting the correct one
I am using a framework email library class Nette. Then at some point, instead of calling the method setSubject - which is the correct method, I called addSubject, because I had forgotten the name of…
-
2
votes1
answer620
viewsHow to get the line number in PHP?
How can I be getting the line number on which the method was executed for example? class.php Class Example { function methodExample() { echo __LINE__; } } index php. include "class.php";…
-
2
votes2
answers4863
viewsHow to create a method with optional parameters in pure Java?
How I create a method that does not need to enter all parameters? Ex. There is a method that asks for 5 parameters. But I intend to use only 2.
-
2
votes1
answer41
viewsMethod returns instance, after setting property
There is a name for the practice or pattern, for this code snippet? Example: <?php class Pessoa { //... public setNome($nome) { $this->nome = $nome; return $this; } //... }…
-
2
votes1
answer51
viewsQcombobox.addItems: called with Wrong argument types
I have the following code: self.option = QComboBox(self) self.option.addItems(self.getJson) def getJson(self): self.data = {'image' : ['planet.jpg', 'cat.png', 'building.jpg']} return…
-
2
votes1
answer426
viewsInstantiate class or use public methods?
When using a class method, there are two approaches: instantiating the class and using the method by the object, or making the method public static and call directly. Is there a problem using one or…
-
2
votes1
answer1149
views"Finish" method in Java
How does the "finalize" method work in Java? It is called implicitly? Below is a code with this method that I cannot understand. The class EmployeeTest calls this method, but I don’t know how.…
-
2
votes3
answers386
viewsCall a single time method within an Event Handler that is called several times?
I would like to know how I do to ensure that a method be called once within a Event Handler C#, whereas this Event is called several times. Example: //meuEventHandler é chamado várias vezes.…
-
2
votes1
answer1688
viewsClick button call different methods
I have a button that calls the click event btn_Salvar in my form. How do I call this event different methods according to who created the form in which the button is contained? EDIT: Explaining…
-
2
votes1
answer2649
viewsHow to calculate 2 n and (2 n)+1 in java?
I am doing a work in which I have to do some calculations with batteries and I need to do tests for powers of two and powers of two plus one, namely 1, 2, 3, 5, 8, 9, 16, 17, etc. The power of two…
-
2
votes2
answers48
viewsCan a static method have the same name as a property?
Since a static method will not be an object method I can have a static method with the same name as a property defined within the constructor?
-
2
votes1
answer36
viewsObject-Oriented Programming Simple Doubt with Implements
I’m using a php library. You have a class with a method that takes as parameter exactly this text that I will write: TextElementInterface $pText = null .In the definition of TextElementInterface he…
-
2
votes0
answers84
viewsMethod calling method
By my knowledge I can only call the method of a class only if I instantiate or if the method is static! I can just do something myself class->metodo('var') or class::metodo('var'). But I’ve seen…
-
2
votes1
answer111
viewsHow to print the name of the method, file and line that was called?
Example: file name: teste.cs A part of the code: ... public void MeuMetodo() { // suponha que essa linha seja a 100 Console.WriteLine("Arquivo: " + arquivo + "Metodo: " + metodo +" linha: " +…
-
2
votes1
answer69
viewsAdd method to an existing c++ class
I wonder if in c++ you can increment an existing class by inserting new methods, without touching the class source code directly. For example, if the class below is part of an external library that…
-
2
votes3
answers556
views -
2
votes1
answer47
viewsThe use and non-use of the word Function in Typescript
Why when I declare method in a class the compiler beeps, stating that the word usage is wrong function. In previous lessons of my learning to create a function I signed first as function. abstract…
-
2
votes1
answer265
viewsWhat is the "right way" to use PHP destructors
When searching for references of good practices in PHP for memory management I came across several intentions of how to use destructors. I know the leading actor is Garbage Collector but this is not…
-
2
votes1
answer536
viewsOverloaded Constructors: Instance Initializer
From the perspective of compiler behavior and java class design what would be the justification for using the Instance Initializer block? Considering the following class: class Caneta { public…
-
2
votes1
answer94
viewsHow to pass an algorithm as parameter in java?
I’m doing some time measurements on sorting algorithms and created this method that calculates the time it takes an algorithm to sort an array of disordered numbers public static double…
-
2
votes2
answers1982
viewsHow to call a method within a System.out.println?
It has how to call a method within a System.out.println(" ");? Follows my code: package ExerciciosReferenciaDeObjetos; public class Aluno { private String nome; private int matricula; private float…
-
2
votes1
answer62
viewsDemand that one method must be followed by another?
Let’s say I have a class with two methods, and the method x must be executed after the method y otherwise the method x must execute the method y to get the value default. class Classe { private…
-
2
votes0
answers324
viewsNewton-Raphson method together with Horner
I’m having trouble implementing Horner’s method to decrease the computational cost of polynomial calculations and, having done so, using Newton’s method to find the root of the polynomial In the…
-
2
votes1
answer38
viewsWhy in a generic-type method extension do I not need to spell out a type when calling it?
In the link below is a code snippet consisting of nothing more than a Shuffle method that is used as a Extension Method of Array. Although the method is generic type, I don’t need to pass a guy when…
-
2
votes1
answer1893
viewsDoubt to create and work with JAVA class array
I have a program with 2 classes. The player class contains only the name attribute: public class player { String name; } And I have the Main Class that has the function below and the call of the…
-
2
votes1
answer43
viewsHow do I compare one object type parameter to another (java)
I have the addCurso method that receives a parameter that is a course type object, it has information such as name and area, all within the College class, which has a vector where these courses will…
-
2
votes1
answer260
viewsCall method with defined vector elements parameter
Good night! I have created a method that calculates the elements of a vector and makes the general mean, but I am not able to call it in the main method. PS: I am a beginner. Thanks for your help!…
-
2
votes2
answers110
viewsC# override autocomplete does not work
I can’t write a superscript with suggestions from override. The completion of the override does not give suggestions of virtual classes or methods as Tostring(). How do I make these suggestions…
-
2
votes1
answer164
viewsIn what order to dispose the methods of a Java class?
In which order to dispose the methods of a Java class? Whereas a class can have: constructors, static methods, private methods, public methods, abstract methods. For example: public class Classe {…
-
1
votes4
answers1506
viewsDirect method call in instance
I came across something that doesn’t seem to make sense, when I try to make the method call from a direct object in its instance it doesn’t seem to work. class Pessoa{ private $Nome; private $Idade;…
-
1
votes2
answers207
viewsMethod and Sub-programme
Both mean the same thing? void subrotina(){}; Isn’t that called method too? People don’t say they’re going to do a subprogram that does something, usually people say, "I’m going to do a method that…
-
1
votes3
answers71
views.length locks all the code
I need to know if the user is logged in through Javascript (jQuery) to run some commands (purely aesthetic). The quickest alternative I could find was to create a hidden input that is only placed on…
-
1
votes1
answer154
viewsCreate partial (partial) method in C#
You can create a method similar to a class that is partial? For example: Has the method $InitializeComponent() which is of the class of a form. I want to increment this function without touching the…
-
1
votes1
answer1714
viewsHow to create a vector that displays the frequency of each element in a matrix?
"Write a method frequency which receives data from a matrix A that has integers between 0 and x; generates a vector with the occurrences of each integer between 0 and x. Write a method greater that…
-
1
votes1
answer850
viewsUsing another class method
I need to execute a method that is in another class. I think the two are non-activityes classes. The following class has a method called connect(). When this method is executed, at the end of it I…
-
1
votes3
answers825
viewsMethod parameter with abstract class
Hello. I believe my doubt is very simple, but I really did not find any solution, after much research. In Java, I have two concrete classes that extend an abstract class, as the example: public…
-
1
votes1
answer199
viewsPointer to method
I started studying object orientation and I’m trying to call pointer to method, but I’m having difficulties. The implementation of the method startAllegro class Application is as follows: void…
-
1
votes1
answer653
viewsMethod within method or class within class
Created the methods Above(), Below(), Highest(), Lowest(), Evens(), Odds(), Matching(), Repeating(), Unique()... I need to create a structure/implement these methods inside each other, as if they…