Most voted "instantiate-object" questions
65 questions
Sort by count of
-
11
votes2
answers252
viewsDifference between instantiating class and using
I can instantiate a class in two ways in C#, they being: HttpClient http = new HttpClient(); or using (var http = new HttpClient()) { // } Is there any difference between these means? Performance?…
-
6
votes4
answers364
viewsDifferent methods of creating an object
What is the difference between these two types of creation/instantiation of an object? Usuario usuario = new Usuario(); usuario.listar(); new Usuario().listar();…
-
6
votes3
answers463
viewsWhat is the correct option to instantiate a PHP class?
What is the correct option to instantiate a PHP class? Whereas the class is under discussion if call Atleta: 1) $atleta=Atleta; 2) $atleta= new Atleta(); 3) $atleta= Atleta(); Which of the 3 options…
-
5
votes3
answers456
viewsInfinite object?
I ended up doing something that made me curious: I created a Cao class to follow: public class Cao { String nomeDoCao = null; Cao caes = new Cao(); public void setName(String name) { nomeDoCao =…
-
5
votes1
answer67
viewsHow to pass argument to Object prototyped with prototype?
With this of to do this: function Biscoito(sabor,marca,preco) { this.sabor = sabor; this.rodas = marca; this.preco = preco; this.mostrarAtributos = function(){ return sabor + ", " + marca + ", " +…
-
5
votes2
answers180
viewsUse Static Closures or Closures in PHP?
As of PHP 5.4, the Closures (Or funções anônimas), when declared within the context of a class method (other than static methods), automatically inherit to "within" the $this as a reference to the…
-
5
votes3
answers2556
viewsHow to know how many objects were instantiated?
In a Java application, how do I know how many objects in a class were instantiated? This doubt came to me by reading the article mentioned in the link below. It follows the excerpt that led me to…
-
5
votes2
answers419
viewsIs it possible to instantiate a class without storing it in a variable?
Normally I do so: $a = new MinhaClass($Parametro); You can do this without creating the variable $a ? Only with the new?
-
5
votes4
answers197
viewsCorrect syntax way in object instance
In the instance of an object, we can: Pessoa pessoa = new Pessoa(); and we can also: Pessoa pessoa = new Pessoa(){ Nome = "Nome", Id = 0, Situacao = true }; What is the best or most correct way to…
-
4
votes2
answers1232
viewsDifferences when instantiating a class
Using the PHP when instantiating an object I do it as follows: $obj = NEW my_class_exemplo; but always the netbeans auto complete gives me the option to put parentheses like this: $obj = NEW…
-
4
votes2
answers10606
viewsWays to instantiate an object and declare constructors
In C++ there are several ways to create a constructor and instantiate an object. But there are so many ways I’m confused by the difference of each. Assuming I have the following class: using…
-
4
votes2
answers577
viewsInstance in Django model with problem
I’m working on a multi-app project. The department app model is as follows:: from emails.models import GerenciarEmails class Departamento(models.Model): #modelo de grupos de disciplinas class Meta:…
-
3
votes1
answer156
viewsInstantiating a class can use it in all functions of the same class
I wonder if I can instantiate another class just once and use it in all other functions of my current class. Sample code: require ('model.php'); class search{ function __construct(){ $objModel = new…
-
3
votes1
answer516
viewsIs it possible to load classes dynamically and use them as a type?
I’m trying to make a code that loads classes dynamically and can use them to create instances and be used for cast. I can create an instance in the newly loaded class using the method…
-
3
votes1
answer66
viewsWhat’s the difference if I instantiate a class within the method or if I instantiate just once?
Instance of a class each time I call the method: public String formatar(int valorFormatar){ DecimalFormat df = new DecimalFormat("###,###,###"); return df.format(valorFormatar); } Now an example of…
-
3
votes2
answers83
viewsObjects eligible for the AG
I have the following certification issue on the Garbage Collector: 1: public class Rabbit { 2: public static void main(String[] args) { 3: Rabbit one = new Rabbit(); 4: Rabbit two = new Rabbit(); 5:…
java objects instantiate-object garbage-collector jvmasked 3 years, 11 months ago Deivson Bezerra 149 -
2
votes1
answer54
viewsDefining the constructor of an Object
Hello, I’m doing exercises on constructors in Java but I’m having a question. I have two classes Main java. public class Main { public static void main(String[] args) { Duck[] d = new Duck[5]; d[0]…
-
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
answer200
viewsSynchronous Creation of Android Surfaceview
I created a subclass of Surfaceview to abstract canvas operations, such as drawBitmap (among others), as shown below: public class MyView extends SurfaceView { public MyView(Context c) { super(c);…
-
2
votes2
answers152
viewsWhat is the difference between instantiation in the same variable or in 3 different variables?
Follows part one: class Pessoa{ String firstName String lastName int age def address static main(args) { def p = new Pessoa() p.setFirstName("Lars") p.lastName = "Vogel" p.address = "Homestreet 3"…
-
2
votes2
answers359
viewsKeyword "new" in C#
I went to see about the keyword new in C#, but I could not find someone who explains well what I want to know. They say that the new creates a new instance, but I don’t understand exactly what they…
-
2
votes1
answer64
viewsDifference of use of immutable object in method argument or outside it
If I have the following String of which it was created: String s1 = "Primeira String"; When using the method: s1.toUpperCase(); nothing happens because an instance has been created and has not been…
-
2
votes1
answer106
viewsMeaning of the parentheses in the instantiation in C#
I can’t understand the need for () to instantiate a class. Retangulo n1 = new Retangulo(); Is it the language’s own thing or has meaning behind?
-
2
votes1
answer74
viewsInstantiating a class "x" from another class "y" inherited by the class "x"
If I have a class Diretor who inherits from the class Funcionario, so I say a direct is also an employee. Public class Diretor : Funcionario{} Diretor diretor = new Diretor(); But I’m allowed to…
-
2
votes1
answer56
viewsWhy instantiating objects using new keyword is hardcoded?
I am learning Spring, and several times I have come across instructors solving the "problem" of instantiation of objects being made by keyword new, as in: private SpeakerRepository repository = new…
-
1
votes1
answer122
viewsError adding new instances in a Javascript array
I’m having the following problem I have an array that adds the instance of an auxiliary object to the instance of an Htmlelement, but only the last element is being added, tested in the Chrome…
-
1
votes2
answers590
viewsHow does creating an Array work?
When using the command new() for the creation of any object we call the constructor of the class of that object and obtain the reference to the instance created. However, what happens when creating…
-
1
votes4
answers110
viewsWhy this division in the class instantiation in C#?
In the book "Use the Head - C#", the author declares classes in a way that I did not understand their usefulness, according to the example: public partial class Form1 : Form { Farmer farmer; public…
-
1
votes1
answer672
viewsStatic method with object as parameter
I am creating a very simple system for enrolling students. I took a class Aluno as follows: public class Aluno { private String nome; private String matricula; private String curso; private int…
-
1
votes1
answer207
viewsInstantiating an entity within another entity: how to do it?
The class Estado depends on the class Pais. What would be the difference between me doing this: And do this? I mean, what’s the difference between me instantiating the class Pais within the class…
-
1
votes0
answers16
viewsApp using canvas does not emulate in Android Studio
I made an app in Android Studio, according to codes below, however, when emulating inside an emulator of Android Studio itself, does not run. There seems to be some problem in the Activity instance,…
android-studio android-activity canvas instantiate-object emulatorasked 3 years, 10 months ago CarlosProg 11 -
1
votes1
answer365
viewsHow to locate an object by name only?
I’m 6 PictureBox, then, when saving the photo in the database, save together in which PictureBox she was. So when uploading the photos in a view, I need each photo to be displayed in its respective…
-
1
votes2
answers108
viewsWhy don’t you instantiate the list so it doesn’t accumulate?
I have the following class: public class TesteLista { public static void main(String[] args) { List<String> dados; Teste1 t = new Teste1(); dados = t.getList(); System.out.println(dados); } }…
-
1
votes2
answers127
viewsUse of the "Instance of"
public class AlunoLicenciatura extends Aluno{ private String curso; private ArrayList<Disciplina> l_dis; public AlunoLicenciatura(String curso,Aluno a){…
-
1
votes2
answers97
viewsHow to assign a class to the whole and not just attributes separately?
I have a class constructor method that when called makes a query in another database class that returns me the same constructor method class(only with the assigned data), example: public Invoice(int…
-
1
votes1
answer249
viewsUsing a PHP class without instantiating it into a variable is the same thing as calling a function?
Declare the class this way without instantiating it into a variable: new ExampleNameClass( 'arg1', 'arg2' ); It would be the same as wearing a function? ExampleFunction('arg1', 'arg2'); Since I did…
-
1
votes1
answer75
viewsHow to prevent an object from being instantiated with a certain property?
I want to prevent an object from being instantiated with a certain value (for example, prevent a "battery" object from having a negative value or above 100). How can I prevent the instance from…
-
1
votes1
answer317
viewsInstances of Singleton Asp.Net Core classes
I have a doubt in the following situation: Singleton Classe namespace TesteSingleton { public class Singleton { private Singleton _singleton; public Singleton() { if (_singleton == null) _singleton…
-
1
votes1
answer58
viewsProblems instantiating objects in python
I’m new to programming, but I just came from Java and I’m migrating to Python.. To start I created a simple Person class with 3 attributes and tried to instantiate it to see the syntax, but I just…
-
1
votes1
answer59
viewsCS0747 Error with C#declared
I have created a list that receives my command object powered by the fields of my Forms, my class: public class Comanda //Essa classe carrega tudo necessário para o pedido. { public int idComanda {…
-
0
votes3
answers262
viewsHow to instantiate a model and get its features by its name in Ruby on Rails
Since I have the abstract class User, and its sub-classes Client Employee and Admin, would like to render screens according to the chosen subclass. So: users/_form.html.erb : shall contain a…
ruby-on-rails ruby mvc abstract-classes instantiate-objectasked 9 years, 10 months ago user5020 1,027 -
0
votes1
answer710
viewsCapture information and use when you need Java
I am thinking of implementing a function that captures the logged in user, I still can not imagine how I can implement such a function, I would like to know what is usual and propitious for me to…
-
0
votes2
answers1505
viewsObject of a class in another Java class
Hello, There is possibility of having the class Object you instanced in the instantiated class? Ex.: (Incorrect syntax, just an assumption) public class Classe2 { // Metodos e vetores da classe }…
-
0
votes2
answers346
viewsDynamic form statement in JAVA
I am doing a work on graphs and need to read in the file the input of data from a file, example : VERTICES 0 1 2 3 4 EDGES 0 1 2 3 After reading the file need to instantiate these vertices and…
-
0
votes1
answer425
viewsWhy isn’t the object being instantiated?
I have a Bean class (Casa.java) public class Casa{ //atribubutos private String parede; public Casa(){ } //getters e setters public void setParede(String parede){ this.parede = parede; } public…
-
0
votes1
answer234
viewsAllow only one instance
How to make my application run only 1 instance at a time? void Main(string[] s){ //faz algo }
-
0
votes0
answers44
viewsInstancias Lentas C#
I am creating an instance of a certain class , and it is taking too long to instantiate . Does anyone know how to solve this ? Suddenly the applications took time to instantiate code of the class…
-
0
votes1
answer872
viewsSession variables $_SESSION vs class variables in PHP
I wanted to know the pros and/or cons of using session variables on class constructor or even within class methods. Let’s say I have the following class: class minhaClasse { private $arrEnvSettings;…
-
0
votes2
answers150
viewsIs it possible for a Closure (Swift) to capture reference of the instance of the object that executes it?
I am passing a closure for the property of an object, and within the closure would need to make a reference to the instance of the object that will run the closure. Example: typealias validator :…
-
0
votes2
answers85
viewserror: use of Deleted Function Fight::Fight()'
Good afternoon, I am experiencing several problems when compiling the code below in the code::Blocks with g++ and I would like to get help, thanks in advance. Content of main.cpp: #include…