Java_test
Java_test
2.1 Question 1
Please find the possible errors in the code in the 3 classes below and try to correct them.
2.2 Question 2
Among this 3 examples of instantiation of class "ProjectBeanCustom", which one(s) is(are)
correct and which one would you prefer to use?
The one that is correct is the first one because it uses one of the correct constructor
ProjectBeanCustom pbc1 = new ProjectBeanCustom("Projet Recruteemnt", 10,
dataSart, dataEnd, "GOING");
2.3 Question 3
In the Java class "ProjectBeanCustom", the attribute ("etat" ) is defined without encapsulation
rule ( public, private, setter , getter...). How will JVM interpret this ?
Means that it is package level attribute, his is visible for this class and all the class that are in the
same package
2.4 Question 4
Describe the hierarchical relationships between classes ( ProjectBeanCustom.java >
ProjectBean.java > ProjectGenericBean.java ) and explain the invoking sequence of these
constructors.
ProjectGenericBean is the ancestor of ProjectBean.java, ProjectBean.java which it the ancestor of
ProjectBeanCustom
which means ProjectGenericBean is the super type of ProjectBean.java and
ProjectBeanCustom.java
and ProjectBean is the super type ProjectBeanCustom
2.5 Question 5
How to save the object ('ProjectBean') with the method (< saveBean >) using the following data ?
To save object ProjectBean, we just need first to created de object with the corresponding data
ProjetBean projectBean = new ProjetBean("Projet Recrutement", 10, Date.today, 12/11/2024,
"GOING")
2.6 Question 6
With the saved data from question 5, what text will display after executing the following code.
It will print the class name and the hascode of the object
2.7 Question 7
Write the method (getDurationToString(String flag)) in the class (ProjectBean).
@Override
public String getDurationToString(String flag) {
flag = flag.toUpperCase
String result = switch (flag) {
case "YEAR" -> this.getDuration().getYears() + "Year(s)";
case "MONTH" -> this.getDuration().getMonths() + "Month(s)";
case "DAY" -> this.getDuration().getDays() + "Day(s)";
default -> throw new IllegalStateException("Invalid Flag: " + flag)
}
return result;
}