Most voted "classes" questions
In object orientation, a class is a structure that abstracts a set of objects with similar characteristics. A class defines the behavior of its objects through methods and possible states of these objects through attributes. In other words, a class describes the services provided by its objects and what information they can store.
Learn more…715 questions
Sort by count of
-
3
votes2
answers837
viewsOperator error cannot be applied to the method group
I’m trying to print a date subtraction using C# with Webforms, but I don’t know how to correctly insert attributes in methods or how to print the method. I’m converting the subtraction of dates into…
-
3
votes2
answers70
viewsSet values inside or outside the method?
I’m studying about passing parameters in PHP. I want, for example, to use a certain method that needs to receive two values, I have the following codes: Example 1 In the class: class Exemplo {…
-
3
votes1
answer149
viewsIn what order does a class inherit from its python superclasses?
Be the code below: class B(A): def __init__(self): self.c = 16 def y(self): print("B.y") def get_c(self): return self.c class C(object): def __init__(self): self.c = 5 def y(self): print("C.y") def…
-
3
votes2
answers883
viewsHow to check if a method exists in a Python class?
How to check if a method exists in a Python class? Is there any function that does this? class Test(object): def method(self): pass For example, I would like to check through a condition if a…
-
3
votes1
answer258
views -
3
votes2
answers553
viewsKnow how many ports are open in Java program
I have a program in Java to know how many doors are open but I’m not sure where to put the method to count the doors. I can create a method to count open doors within the class Porta? package…
-
3
votes1
answer244
viewsWhy can’t I pass a parameter to the class?
I’m trying to pass the parameter "ink" to the class "Pen" but I can’t. I’ve tried using boolean expressions instead of index, but still no result. Could someone give me a help? class Caneta(): açao…
-
3
votes1
answer277
viewsKnowing which class of daughter the parent class points to
I came from Java and I have a question about polymorphism in C++. Given these classes: class Empresa{ vector<Pessoa> pessoas; int empregados; addPessoa(Pessoa* p) } class Pessoa { ... }; class…
-
3
votes2
answers57
viewsInitializing Array from a new class
Considering two classes in C#: public class aClass { public string afield; } public class bClass { public aClass[] bfield; } I plan to start the variable as bClass cVar = new bClass();…
-
3
votes2
answers85
viewsClass declaration in Java
I can declare more than one class in the same Java file, and if this is possible, it is the most correct way to program in this language?
-
3
votes1
answer994
viewsDifference between type inheritance and implementation inheritance
My teacher passed a booklet on Object Oriented Data Structure with Java and in the booklet there is an excerpt (without deepening) that says the following: "Interface promotes heritage of type and…
-
3
votes2
answers2246
viewsDoubt in class diagram
Good afternoon. Follow the question about class diagram with the diagram I was able to do. Describe the class diagram for a simple room reservation and occupancy system for a hotel. The system must…
-
3
votes1
answer690
viewsWhat is the difference between classes initialized with (and without) __init___
I’m a beginner in Python and I wanted to understand a difference. The two classes below produce exactly the same result and the variables become public in the same way in both classes: class c(): t…
-
3
votes1
answer104
viewsIs there any relevant difference between "Object-oriented programming" and "Class-oriented programming"?
I was reading a post that member @Maniero indicated, and I came across a response from another member that raised more questions and decided to search. In the answer was the following phrase:…
-
3
votes1
answer80
viewsHow can a class also be a method in Ruby?
See the class Integer: Integer.class => Class It also seems that it is a method, at the same time that it is a class: Integer 10.5 => 10 How is this possible in Ruby? Where is this method…
-
3
votes2
answers904
viewsHow to access properties of an object that is inside another object?
Deep down I want this output Console.WriteLine(cidade1.casas.dono); returns João using System; namespace arrayteste { public class cidade { public string nome { get; set; } public object casas {…
-
3
votes2
answers140
viewsMaximum number of classes in Java
I was doing some exercises of the course and I came up with a question. If I create a project in Eclipse and in it I will include my classes, assuming that each class is a specific exercise, each…
-
3
votes1
answer2462
viewsPut multiple classes in the same file
In my project I have the class main and created new Java class files with Netbeans to define the objects there. I can only use in main one of the classes, the others I can’t even call the methods.…
-
3
votes1
answer193
viewsSome Python codes display "__class__" when creating certain classes. What is it for?
I realized that in certain codes in Python is used a __class__. What good is the same? Example: class abstract1 (object): def __init__(self): if self.__class__ == abstract1: raise…
-
3
votes2
answers154
views -
3
votes1
answer42
viewsHow to handle an error within any Python class?
If I do something like: class Foo(object): pass print(Foo().python) **OUTPUT:** AttributeError: 'Foo' object has no attribute 'python' How can I treat this exception within my class, rather than…
-
3
votes2
answers61
viewsDo generic Helper/Utility classes hurt the Single Responsibility Principle (SRP)?
The classes Helper/Utility with generic methods, which are used for various purposes, violate the Single Liability Principle (SRP)? The following is an example of some methods in the class: function…
-
3
votes2
answers60
views -
3
votes1
answer94
viewsJSON Return to JAVA Class Conversion Error
I have a java class public class PRODUTO extends SugarRecord implements Parcelable { private float id_pro; public PRODUTO(float id_pro){ this.id_pro = id_pro; } public float getId_pro() { return…
-
3
votes1
answer36
viewsIf the class ofstream is to write to files, ifstream to read and fstream to both cases, why not always use fstream at once?
Even if we wanted to read, write, modify, create, delete files, or other operations, we could no longer use the class fstream? What problems could they generate if you don’t use those specific?…
-
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
answer106
viewsClass definition within a function or another class
I’ve seen in some scripts definitions of classes within other classes or functions like this: class Grok(object): class Foo(object): ... ... What is the reason for this practice? It is only to not…
-
3
votes4
answers4102
viewsHow to return the values of a List<> in C#
I have a class Funcionario which has as attributes: CPF, Nome and Salario. I have to create an X amount of instances of this class in a List<> and after that, return to the user the values of…
-
3
votes1
answer101
viewsWhy is the "private" access modifier letting me change the attribute outside the class?
Well, I have this class with the attributes private class Conta { int numero; // Atributo private double saldo; Cliente user = new Cliente(); private double limite; } From what I understood of the…
-
3
votes1
answer134
viewsVariables and methods in the abstract class, where to put?
Cliente and Fornecedor has name, phone and email in common what is the best way for me to treat this, should I create these variables in common in the abstract class? or is there a better way for me…
-
3
votes1
answer56
viewsWhat is the reason for using "super()" before creating daughter class variables?
I found this question which speaks almost of the same subject but her focus is on access to parent class methods. And my doubt is to know why the use of super() before the declaration of variables…
-
3
votes1
answer101
viewsAre there advantages to using closures to maintain state rather than class?
It is very common to use classes to encapsulate state and some methods that modify it, such as this counter: class Counter { #val = 0; increment(step = 1) { this.#val += step; } retrieve() { return…
-
2
votes3
answers346
viewsHow to make a polymorphic pointer with the this pointer in the parameter?
For example, in Qt (correct me, if the logic is wrong, I haven’t touched Qt in a while), you can do this: QLabel label = new QLabel(this); Now let’s suppose: #include <iostream> class…
-
2
votes2
answers211
viewsDoubt about inheritance in classes
How to do the if controller return TRUE or FALSE in accordance with the check() of the Validator? Currently it returns boolean to the validate();, but I wanted it to continue until the end of the…
-
2
votes2
answers4223
viewsDynamically create PHP class instance with Namespace
$class = ucfirst(strtolower($_GET['type'])) . "Controller"; include $class . ".php"; $item = new $class(); But I put the class name without being dynamically, for example: $item = new…
-
2
votes2
answers343
viewsUsing Flash Professional, how to import classes from an Actionscript file?
In my project I have the Listloader class, responsible for interpreting a list and uploading files described in it. My goal is to save, this and other classes, in a file extension ". as" and be able…
-
2
votes3
answers1471
viewsHow do I use a constant within a class method?
I defined a constant in a file and would like to call it within a method in a class. Example: Filing cabinet: Configuracao.php <?php define('FOO','Hello World'); require_once('Classe.php'); ?>…
-
2
votes2
answers181
viewsCall a new IOS class
I’m new in IOS environment and after studying a little how the language works, I did not understand how I can call a window/ class and overlap the current window as I do on android. Intent intent =…
-
2
votes1
answer727
viewsWhat is the difference of implementing classes in C++ and PHP?
I am currently working in PHP and realized that when implementing classes I can’t just instantiate and then implement below the class using the scope selector ::. Example: class Lista{ public:…
-
2
votes1
answer547
viewsInstantiate class outside namespace
I have a class with the namespace defined: namespace App; class AppSessionHandler { private $db; //... $this->db = Utils::ZendDB(); >>>>>> LINHA 12 } The following error occurs:…
-
2
votes1
answer1551
viewsGet self variables from another class and custom event
Read only comments in English, the question of self is in comments in the code, now the events will be down there. class LOL: class Champions: class MasterYi: def __init__(self): #YiAttributes…
-
2
votes1
answer1754
viewsHow to modify or set a value within the class in php
I have a class in the php and need to modify the value of private $key = "valor"; out of class. How can I change the value of $key out of this class? The value I want to put in $key comes from a…
-
2
votes0
answers48
viewsWhen to use static classes?
For example within a framework, should I use static classes only for features like freight calculation, form generators, media upload? or for example I can use a static class for the MVC…
-
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
answer97
viewsDecrease responsibility of a class
I recently had the need to work with object-oriented sessions and created the following class: https://github.com/mateusdemboski/PHPsessionManager/blob/master/src/Session.php <?php /** * @author…
-
2
votes1
answer385
viewsClass derived from Printdocument class C#
I have a class to print labels (Cprint), this class is derived from the class PrintDocument. It takes an image calling a method contained in the class Form1.cs. Follow the code of the class…
-
2
votes1
answer138
viewsWhat does "Inconsistent modifiers style" mean in Resharper?
Resharper is suggesting the following change in code: Obs: To classe Pagamento has public methods. Why the suggestion internaland not public?…
-
2
votes1
answer232
viewsWhy should I use File::copy, if PHP already has copy?
I am using the Laravel in various projects that I use. I needed to copy a particular file from one location to another, and I saw in the Laravel documentation that I should use File::copy(). Out of…
-
2
votes1
answer150
views -
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…