exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 171 discussion

Actual exam question from Oracle's 1z0-808
Question #: 171
Topic #: 1
[All 1z0-808 Questions]

Given the code fragment:

Test.java:

Which is the result?

  • A. Compilation fails in the Employee class. B. C.
  • D. Compilation fails in the Test class.
  • E. Both the Employee class and the Test class fail to compile.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MPignaProTech
2 months, 3 weeks ago
No default constructor was provided. Correct response is D
upvoted 1 times
...
carloswork
2 years, 2 months ago
Selected Answer: D
Answer is D. Employee class is ok. In the test class, as informed by Snover, the error is thrown because an object is instantiated without respecting the arguments presented in the constructor. To test, Employee Class: class Employee { private String name; private int age; private int salary; public Employee (String name, int age) { setName(name); setAge(age); setSalary(2000); } public Employee (String name, int age, int salary) { this(name, age); setSalary(salary); } public void setName(String name){this.name=name;} public void setAge(int age){this.age=age;} public void setSalary(int salary){this.salary=salary;} public void printDetails() { System.out.println(name + " : " + salary); } }
upvoted 2 times
carloswork
2 years, 2 months ago
To test, Test Class: public class Test { public static void main(String[] args) { Employee e1 = new Employee(); // Error Employee e2 = new Employee("Jack", 50); Employee e3 = new Employee("Chloe", 40, 5000); e1.printDetails(); e2.printDetails(); e3.printDetails(); } }
upvoted 1 times
...
...
iSnover
2 years, 3 months ago
Selected Answer: D
The letter D is correct, because in the Test class the variable e1 was instantiated with an empty constructor, but in the Employee class there is no empty constructor, so a compilation error occurs.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago