Return to site

JAVA CERTIFICATION QUESTION: Java records as instance inner classes

=>Digging into the behavior of Java records, including implicit references

· java

Given the Computer class:

class Computer {
 private String cpu = "Intel";
 class Report {
  String getReport() {
   return "Computer with " + cpu + " CPU";
  }
 }
}

 

Your colleague is working on refactoring to use a record to generate the report.

How can this be achieved? Choose one.

A)

record Report {
 String getReport() {
  return "Computer with " + cpu + " CPU";
 }
}

 B)

record Report() {
 String getReport() {
  return "Computer with " + cpu + " CPU";
 }
}

 C)

record Report() {
 String getReport() {
  return "Computer with " + Computer.this.cpu + " CPU";
 }
}

 

D) None of the above.

 

 

 

 

·ꓷ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ