Exercise 03: XBCS1093 Java Programming
Exercise 03: XBCS1093 Java Programming
Exercise 03
$ javac main_class.java
Exception in thread "main" java.lang.Error: Unresolved compilation
problem:
Duplicate local variable x
Compilation error.
Two variables with the same name can’t be created in a class.
10 5
Arrays in java are implemented as objects, they contain an attribute that is
length which contains the number of elements that can be stored in the array.
Hence a1.length gives 10 and a2.length give s 5.
XBCS1093 Java Programming
The class Publication has one constructor with arguments (String title,
Author [] a, Date date) that sets the values of the four instance variables to
those passed as parameters.
The class Publication has second constructor with arguments (String title,
int nbr, Date date) that sets the values of instance variables to those passed
as parameters and create the array of authors with nbr authors.
Finally, it defines the toString() method that returns the string in the format
“author1, author2,… , [title], publicationDate”.
Implement the class Publication.
public abstract class Publication {
numberofAuthors = a.length;
}