0% found this document useful (0 votes)
3 views

Java_test

The document contains a Java test for a candidate named Happy Paul Fernand, focusing on identifying and correcting errors in code related to class implementations and instantiations. It discusses issues such as abstract function implementation, encapsulation, and class hierarchy, along with providing code snippets for saving objects and method definitions. Additionally, it includes a specific method implementation for converting duration to a string format based on a flag input.

Uploaded by

drivesankofa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java_test

The document contains a Java test for a candidate named Happy Paul Fernand, focusing on identifying and correcting errors in code related to class implementations and instantiations. It discusses issues such as abstract function implementation, encapsulation, and class hierarchy, along with providing code snippets for saving objects and method definitions. Additionally, it includes a specific method implementation for converting duration to a string format based on a flag input.

Uploaded by

drivesankofa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

candidate: Happy Paul Fernand

Efficy Java Test

2.1 Question 1
Please find the possible errors in the code in the 3 classes below and try to correct them.

differents errors I noticed are:


- No implementation of the abstract function "public abstract String getDurationToString(String
flag)" in ProjectBean;
- in the class ProjectBean, the variable "int numero" is public,will should put private for more
coherence
- in the class ProjectBean will should annotation "@Override" on top of function "toString" cause is
a function inherited from java Object Class
-

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")

ProjectGenericBean.saveBean(session, projectBean.toString(), ProjetBean.class, true)

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;
}

You might also like