Constructors
Methods
Fields
1
2
3
4
0
...
Person
object
Person p = new Person();
p
int count = 4;
count 4
Which of the following are valid Java code segments?
int y = 3;
A a;
a = new A();
B b = make B();
int x = 3;
x.add(1);
Q1
public class Person {
private String name;
public Person () {
this.name = "Unnamed Person";
}
public void setName(String name) {
this.name = name;
System.out.println("Now my name is " +
this.name);
}
public String getName() {
return name;
}
}
public class Main {
public static void main(String[] args) {
Person harry = new Person();
Person hermione = new Person();
harry.setName("Harry");
hermione.setName("Hermione");
ArrayList<Person> people =
new ArrayList<>();
people.add(harry);
people.add(harry);
people.add(hermione);
Person someone = people.get(1);
someone.setName("Ron");
}
}
Q2
Hypothesis driven debugging: making careful educated guesses, with plans for how to validate or invalidate them.
Branch: main
Branch: myfavoriteanimal
Create
Branch
Merge
Branch
Commits