Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the output of the following code; package classarray3; public class Clas

ID: 3573546 • Letter: W

Question

What is the output of the following code; package classarray3; public class ClassArray3 {public static void main(String[] args) {System.out.println("loading an array with class instances "); employee [] emp = new employee[3]; emp[2] = new employee(1, "Joe", "Smith", "01/01/2015"); emp[1] = new employee(2, "Ali", "Mohamed", "01/15/1915"); emp[0] = new employee(3, "Joe", "Smith", "01/01/2015"); System.out.println("printing "); System.out.printf("%10s %30s %30s %30s ", "Employee Nbr", "first name ", "Last Name", "Date of birth "); for(int j=0; j

Explanation / Answer

Hi, The question is incomplete as we donot have the declaration of employee class hence the method definition of emplyeePrint is also missing.

Going through the current code snippet, following will be the output.

loading an array with class instances

printing

Emplyee Nbr first name Last Name Date of Birth

Explanation:

1. The flow of the program starts with the main method. Hence the first command in the method will be executed which is printing of a statement on the console.

2. Next in the code, an object array is created of type employee class. Also, in the following statements, we are assigning certain values to these objects of employee class.

3. Then again we are printing certain text on the console using println() method.This method displays the text in new line.

4. Next we are using printf() method to display text on the console. This method is generally used when you have to format the string before displaying it on console. The format specifier "%s" specifies that the value to be displayed on this position of the screen is a string value. Similarly to display an integer we use %d, for float %f ans so on..

5. Here if we see we are also using something like "%10s". This is a format specifier generally used to display data in a tabular manner. Here the number denotes the number of spaces to be added before the string. So "%10s" will right justify the string meaning it will add 10 spaces before the string.

6, Next we are using a for loop to traverse each object one by one from the object array, and display employee information. The output could not be completed as complete question was not their in the image..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote