Questions tagged as 'construtor'

3
answers

What to do when the argument passed in the constructor is invalid?

I'm doing a card game in Java, and one of the classes takes responsibility for starting the game. In the constructor, I get the number of players that will participate. I am doing the validation of the amount of players in the constructor itse...
asked by 27.09.2017 / 23:32
3
answers

Is it mandatory to put the same attributes in different constructors?

I have these builders: // 1st Builder - Create a bike with a new frame public Motociclo (String marca, String modelo, float peso, int robustez) { //Nivel 2 this.marca = validarMarca(marca); this.modelo = validarModelo(modelo);...
asked by 05.12.2018 / 19:59
3
answers

How does initializing fields in constructors work?

In the C # documentation it is written:    If a class does not have a constructor, a default constructor is automatically generated and default values are used to initialize the object fields. That is, if a class does not have a construct...
asked by 01.02.2016 / 20:39
2
answers

Empty constructor without super () call

When I make parameterized constructors, I create an empty constructor as well. In the empty constructor, should I always make the super () call? Because? (Take into account, that my class is just a JavaBean.)     
asked by 15.01.2016 / 12:54
1
answer

Data initialization of a class

Is there any class initialization function for C ++? In Lua, using the classlib library there is the __init function, and in Python as well. EX: require "classlib" Human = class(); function Human:__init(name, age) self.nam...
asked by 20.12.2014 / 01:26
1
answer

When to use magic method __contructor or set and get

My question is regarding builder, for example, I have a class with name, age. the correct one is to use __constructor to pass values to them or use set and get?     
asked by 28.12.2014 / 04:10
3
answers

Builder builder?

I would like to understand why this class has two constructors and why one of them has everything inside this and not separate as in the other. Does that change anything? Normal constructor: public Conta(Correntista correntista, String...
asked by 24.06.2017 / 17:36
2
answers

How does the declaration instance of Table in Lua work?

In object orientation, you usually create the class first and then instantiate it. PHP example: class Test{ public function __construct() { // inicia as parada aqui } } $test = new Test; But in Lua it always s...
asked by 11.12.2015 / 15:34
4
answers

Use of setters in the constructor

I would like to know if there are any semantically speaking differences between these two constructors: public Aluno(String n, float n1, float n2) { this.nome = n; this.setNota1(n1); this.setNota2(n2); } and public Aluno(String n...
asked by 02.11.2015 / 03:20
3
answers

How to use constructor overload in TypeScript?

In languages with C #, for example, you can use the builder overload as shown below: public class Teste{ public Teste(bool a, int b, string c){ } public Teste(bool a, int b){ } public Teste(bool a){ } } After...
asked by 11.10.2016 / 19:52