Questions tagged as 'instanciar-objeto'

1
answer

Instantiating a class and using it in all functions of the same class

I would like to know 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 Model();} fun...
asked by 01.01.2016 / 03:26
1
answer

Is it possible to load classes dynamically and use them as type?

I'm trying to make a code that loads classes dynamically and can use them to instantiate and be used to cast. I can create an instance in the newly loaded class using the minhaclasse.newInstance() method, but I can not use the newly loade...
asked by 01.04.2016 / 15:49
2
answers

Why do not you have to instantiate the list to not 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); } } Class that has method...
asked by 26.09.2017 / 20:12
1
answer

What's the difference if I instantiate a class within the method or if I instantiated only 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 making a single instance of the cl...
asked by 24.04.2017 / 15:08
1
answer

Defining the constructor of an Object

Hello, I'm doing exercises on Java builders but I have a question. I have two classes Main.java public class Main { public static void main(String[] args) { Duck[] d = new Duck[5]; d[0] = new Duck(); d[1]...
asked by 27.07.2014 / 01:28
1
answer

Android SurfaceView Synchronous Creation

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); this.canvasHolder = this.ge...
asked by 10.12.2015 / 15:05
4
answers

Why this division in class instantiation in C #?

In the book " Use the Head - C # , the author declares classes in a way that I did not understand their utility, according to example: public partial class Form1 : Form { Farmer farmer; public Form1 () { InitializeComponent(...
asked by 30.01.2017 / 18:55
1
answer

Using a PHP class without instantiating it in a variable is the same as calling a function?

Declare the class this way without instantiating it in a variable: new ExampleNameClass( 'arg1', 'arg2' ); Would it be the same as using a function ? ExampleFunction('arg1', 'arg2'); Since I did not store a variable, the class execute...
asked by 16.07.2018 / 06:02
2
answers

How to assign a class to the whole and not only the attributes separately?

I have a class constructor method that when called makes a query in another database class that returns me the same class as the constructor method ( only with assigned data ), eg public Invoice(int id) { CallDB db = new CallDB(); Invoic...
asked by 29.12.2017 / 13:41
2
answers

How does creating an Array work?

When using the new() command to create any object, we call the constructor of that object's class and get the reference to the created instance. However, what happens when creating an Array? Where do you point to (I know this term is i...
asked by 14.03.2016 / 13:11