This class includes a constructor that begins on line 8; however, it contains an error. Describe the error. 2. Rewrite the constructor header on line 8 with the error identied in part c of this question corrected. 3. Demonstrate how you might overload the constructor for this class. Write only the header. 4. Write a line of Java code to create an instance (object) of this class. Name it someAuthor. 5. Write a line of code to demonstrate how you would use the someAuthor object created in question 4 to change the author's name to "Stephen King". 6. Write a line of Java code to call the winsAPulitzer method of the Author class using the someAuthor object created in question 10.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
public class Author
2 {
3 private String name;
4 private int numberOfAwards;
5 private boolean guildMember;
6 private String[] bestsellers;
7
8 public String Author()
9 {
10 name = "Grace Random";
11 numberOfAwards = 0;
12 guildMember = false;
13 bestsellers = {"Minority Report", "Ubik", "The Man in the High
Castle"};
14 }
15
16 public void setName(String n)
17 {
18 name = n;
19 }
20 public String getName()
21 {
22 return name;
23 }
24
25 public void winsAPulitzer()
26 {
27 System.out.println(name + " gave a wonderful speech!");
28 }
29 }
1. This class includes a constructor that begins on line 8; however, it contains an error. Describe the error.
2. Rewrite the constructor header on line 8 with the error identied in part c of this question corrected.
3. Demonstrate how you might overload the constructor for this class. Write only the header.
4. Write a line of Java code to create an instance (object) of this class. Name it someAuthor.
5. Write a line of code to demonstrate how you would use the someAuthor object created in question 4 to change the author's name to "Stephen King".
6. Write a line of Java code to call the winsAPulitzer method of the Author class using the someAuthor object created in question 10.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps