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
-
48
votes3
answers24523
views -
39
votes3
answers25089
viewsWhat is the function of a static method?
Is it just convenience? I mean, it’s unnecessary to instantiate an object to use a function that doesn’t use the data from it. Is there a difference in execution? Memory, processing - resources in…
-
33
votes3
answers3113
viewsWhy is it mandatory to implement "public Static void main (String [] args)"?
Why it is mandatory to implement this method in a Java application?
-
29
votes3
answers5730
viewsWhen should we declare a method static?
As a general rule, it is considered bad programming practice to use static methods. But in what situations it is justified (or not justified)? For example: if I were to create a simple method to…
-
25
votes4
answers5615
viewsWhat is the difference in the use of the Equals method for the ==operator?
What is the difference in the use of the method Equals for the operator == in situations of comparison between (1) value types and (2) reference types?
-
17
votes1
answer11086
viewsHow to check the execution time of a method?
Example: I have the Metodo1 and the Metodo2 both have different processing and actions. I want to check how long each takes to run. How do I do that?
-
17
votes2
answers560
viewsWhy shouldn’t I change the "getter" s and "Setter"s?
I recently came across a friend saying that it is not advisable to change getters and Setters. I had made the modification of a Setter of a List. In it I did not receive a list by parameter, but an…
-
17
votes4
answers1286
viewsHow many parameters should a method have?
What is the maximum number of parameters a method should have? When one must consider that there are too many parameters? And what to do in that case? Tupiniquim and object-oriented version of the…
oop software-engineering method parameters software-projectasked 7 years, 7 months ago Piovezan 15,850 -
17
votes1
answer5166
viewsWhat are the reasons to choose between camelCase and Pascalcase in method names?
First, I’m not interested in what you like best or what you use in your language, I want to know the motivation to choose one or the other pattern in a hypothetical language. Second, this is a bit…
characteristic-language method encoding-style ux language-designasked 5 years, 6 months ago Maniero 444,682 -
15
votes5
answers1643
viewsDifference between private and final methods
Studying methods and final classes in Deitel’s book "How to program in Java 6 ed." I came across the following proposition: The declared private methods are implicitly final because it is impossible…
-
14
votes2
answers1007
viewsHow does a method that can receive multiple parameters work?
According to the C documentation#: The method String.Format is responsible for converting the value of objects in strings based on the specified formats and inserts them in another character string.…
-
14
votes2
answers2108
viewsAre function and method the same thing?
When we talk about methods and functions, we are talking about the same thing? For example: function blablabla blabla That is a method?
-
13
votes2
answers618
viewsHow to list methods of a class in C#?
Again I have to say this: I come from PHP and am learning C# now. I usually like to list the methods that the class has, because I always did this in PHP, to test or debug. $a = new ArrayObject();…
-
12
votes2
answers5497
viewsHow to perform method overload with PHP?
How to perform method overload with PHP? To declare methods with the same name but with different parameters.
-
12
votes1
answer751
viewsWhat is the method group?
Coding in C# I ended up making a mistake, perhaps by familiarity with other languages that I usually work, and forgot the parentheses. string.Concat(numero.ToString, "A") I got the following…
-
12
votes3
answers1771
viewsWhat is the purpose of the magical __clone method?
In PHP we have the magic method __clone. It serves to define a behavior when you clone an object through the keyword clone. So far so good. But I did not understand very well why to have this…
-
12
votes3
answers172
viewsWhat is the difference in the 3 types of variables and how do they behave in the compiler?
For test questions, I made the following code: static int valor1 = 10 / 5; static int valor2() => 10 / 5; static int valor3 => 10 / 5; public static void Main() {…
-
11
votes1
answer1648
viewsDifference between method and constructor?
Reading a friend’s notes I came across the following statement: "method does not allocate space in memory". This statement is correct? It may not be the main difference between them, but it is…
-
11
votes3
answers2425
viewsWhy in Java is the size of an array an attribute and a String and a method?
In Java, the size of a array of any object can be obtained with length, which would be an attribute. But in the case of String is length(), a method. However, if you have a array of String, uses…
-
11
votes2
answers160
viewsEqual sign in Ruby method definition
I have come across the following definitions of methods and I would like to know the difference between the first definition and the second. This first has no equal sign in the definition: def nome…
-
10
votes2
answers6412
viewsWhat is the C++ copy builder for? How do I implement it?
I am a programmer Java and I am currently studying C++. In addition to the "normal" constructors (the standard constructor and the parameterized), C++ has a copy builder. I would like to know what…
-
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?
-
9
votes2
answers717
viewsReceive variable value without passing parameter
I have the following method: private string toCamelCase(string text) { text = string.Format("{0}{1}",text.Substring(0, 1).ToLower(),text.Substring(1)); return text; } To use it I need to call it…
-
9
votes1
answer1492
viewsLibraries, interface, classes and methods
What’s the difference between libraries and interfaces? For example, on the line: import java.util.Scanner; The util would be the interface and Scanner the class? Or the util would be the library…
-
9
votes1
answer120
viewsDifferences between readonly Func<> and method
Forgetting a little questions like readability, what would be the differences between the following calls? readonly Func = (T1, T2) => { Return default(Tresult); } private readonly Func<int,…
-
9
votes1
answer147
viewsPHP 7 - Why does a method that returns the primitive String type not generate an error when returning a Boolean value?
PHP 7 - Why a method that returns the primitive type String, does not generate error when returning a value Boolean? <?php class Foo { public function bar() : string { return true; } } $Foo = new…
-
9
votes1
answer98
viewsWhat are the benefits of using the => operator in common methods that are unrelated to Lists or Lambda Expression?
I asked the following question: What value is checked in a condition operation with a variable value assignment? and the user @Maniero answered me, however, in the reply he used an operator and that…
-
8
votes5
answers436
viewsRefactoring: When is a method "too big"?
I’m with a project that "recovers" certain information from an HTML page, makes a parse with the help of Beautiful Soup and return the values in the form of Dictionary, so that in another method I…
-
8
votes1
answer1127
views -
8
votes2
answers925
views -
8
votes1
answer2455
viewsIs the __destruct method useful?
I read about the method __destruct these two links: http://php.net/manual/en/language.oop5.decon.php https://stackoverflow.com/questions/7240230/is-the-destruct-method-necessary-for-php And I still…
-
8
votes3
answers8112
viewsIs there any way to pass methods as a parameter?
In Java, I can pass methods as parameters? Example: public class Teste { public String metodoA(){ //faz alguma coisa } public void metodoB(double numero){ //faz alguma coisa } public void…
-
8
votes2
answers2113
viewsHow to create methods on an Enum?
I have an application in Java and am porting it to C#. I have a question regarding enum that seems to work differently from Java. After asking a question here on the site (Enumerations may contain…
-
8
votes1
answer428
viewsWhat are the differences between the methods "equals()", "compareTo()", and even "=="?
I am aware that there are differences between comparing objects using equals(), compareTo() and even the operator ==, but in detail what are the differences between them and the care we should take…
-
8
votes4
answers814
viewsWhy can’t we return a void call in a void return waiting method?
I was doing some C# tests to find out how the return issue works void. I did the following test below and realized that tests 1 and 3 work perfectly, however 2 no. Behold: public class Program {…
-
8
votes1
answer150
viewsIs there any way to decrease the size of a function’s call?
Example: StringFormats.DateTimeToShortDateStrPtBR(); If you add this method several times in the same line the code will be very extensive, repetitive and confusing. The method is just an example,…
-
7
votes2
answers167
viewsProblem with the magic method __call
I’m trying to use the magic method __call and the function call_user_func_array to recover the method name to be able to upload a file. I am doing it as follows //Classe que importa os objetos $obj…
-
7
votes2
answers327
views -
7
votes1
answer153
viewsWhat is an equal input parameter (allocation operator)?
I have a function defined as follows: public classeDeRetorno nomeDaFunção(string param1, string param2, string param3 = "") What does the param3 = ""? It equals the parameter to ""?…
-
7
votes3
answers1496
viewsWhy is it possible to define two or more methods with the same name in the same class in C#?
I’m starting my C# studies with ASP.NET MVC today. I’m still adapting to some things I’m not used to seeing, because I know languages like PHP, Python and Javascript. I realized that in a code that…
-
7
votes1
answer1855
viewsWhy use const after function?
I noticed some codes from other C++ programmers that use functions like: bool CClass::isRunning() const { return this->_running; } I understood that in this way it is not possible to modify any…
-
7
votes1
answer424
viewsWhat is the difference between using normal methods and Action or Func?
public Action<string> Escrever = (texto) => { Console.WriteLine(texto); }; Might call it that Escrever.Invoke("Algum texto aqui dentro"); VS public string Escrever(string texto) {…
-
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
votes1
answer5290
viewsMethod that returns a class
I am trying to create a method that takes a string and returns an instance of the class with the name passed, example: "Calculator", will return me an instance of the class "Calculator" (If it…
-
6
votes2
answers436
viewsDelegates and methods
When to use delegates? Being that a delegate points to a method, it is not the same thing as creating a normal method? What’s the difference and when to use and why to use? It’s better? Is worse?…
-
6
votes1
answer283
views -
6
votes2
answers191
viewsDoes the List<T> Method. Foreach exist?
I’m trying to implement the example of this page, but VS2015 (.NET 4.5) says the method ForEach() there is no class Program { static void Main() { List<String> names = new…
-
6
votes2
answers982
viewsCalling function from its name in a PHP class
I am creating an application where I need to call the function based on its name within the class. the intention to use this way is that I can call these functions through ajax and the server will…
-
6
votes1
answer201
viewsWhy are you giving this Static variable error?
Why is giving this build error and how can I fix it? Cannot make a Static Reference to the non-static field service…
-
6
votes2
answers840
views