2
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"
println(p.firstName + " " + p.lastName);
println ""
p = new Pessoa(firstName: "Peter", lastName:"Mueller");
println(p.firstName + " " + p.lastName);
println ""
p = new Pessoa(firstName: "Aline", lastName: "Gonzaga")
println (p.firstName+" "+ p.lastName)
}
Follows part two:
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"
println(p.firstName + " " + p.lastName);
println ""
def p1 = new Pessoa(firstName: "Peter", lastName:"Mueller");
println(p1.firstName + " " + p1.lastName);
println ""
def p2 = new Pessoa(firstName: "Aline", lastName: "Gonzaga")
println (p2.firstName+" "+ p2.lastName)
}
My doubt would be on p1
and p2
of the second example. Why are there these two forms of instantiation? What is the best option to do this? Explain to me why the first way is like that and the second way is the other way. It has to do with performance?
Lars Vogel Peter Mueller Aline Gonzaga This is printed. the two forms print alike, how can one superimpose the other? , that part of the state as such? I did not understand...
– Aline Gonz
The variable
p
is storing theLars
, then she stores thePeter
and then it goes on to store theAline
. It’s like you sayx = 1
and then sayx = 2
. It’s that simple.– Maniero
but what about printing? Lars Vogel Peter Mueller Aline Gonzaga .
– Aline Gonz
You don’t know anything about programming then? He’s having people’s names printed up. I don’t know what the question is. For example, it helps to understand the use of variables.
– Maniero
If x=1 and then x=2 would not print 2?
– Aline Gonz
I think I understand, the secret is in the position of the println.
– Aline Gonz
If I do x = 1 println x x=2 println x Print 1 and 2. : )
– Aline Gonz
That’s right. Programming follows a stream. Order is fundamental. This is the basis of every code.
– Maniero
right! I get it.
– Aline Gonz