IMPORTANT: Unless otherwise stated, all of the questions on this page pertain to programming in Java.
Do not consider any other programming language in your answer, unless the questions specifically calls for it.
public final class Foo { ... // code continues from here
In this context, what does the word final
signify about the class Foo
?
GauchoCodeViolationException
public class GauchoCodeViolationException extends Exception {}
java.awt.event.ActionListener
)ActionListener
be useful?this
object be the one that that is acting as the ActionListener, then the advantage is different. In this case, both designs have the advantage that the actionPerformed() method has direct access to the private instance variables and methods, so that isn't the crucial distinction. In this case, instead, the advantage you may cite is that, since you can have more than one inner class implement ActionListener, you can create different ActionListeners that behave differently for different widgets. If "this" is the only ActionListener, then you only get one "flavor" of ActionListener.Book.java, Product.java, Shippable.java, Song.java
1 | public class Q1 { |
2 | public static void main (String [] args) { |
3 |
|
4 | Book gp = new Book("Pratchett","Going Postal",799,0.15); |
5 | Song br = new Song("Lady Gaga","Bad Romance"); |
6 | Product slts = new Song("Nirvana","Smells Like Teen Spirit",79); |
7 | Shippable hp = new Book("Rowling","Harry Potter & the Polymorphic Polyp",652,1.5); |
8 | Shippable ttc = new Shippable("Dickens","Tale of Two Cities",999,1.5); |
9 |
|
10 | System.out.println("a:" + gp.getTitle()); |
11 | System.out.println("b:" + br.getArtist()); |
12 | System.out.println("c:" + br.getPrice()); |
13 | System.out.println("d:" + slts.getPrice()); |
14 | System.out.println("e:" + slts.getTitle()); |
15 | System.out.println("f:" + hp.getPrice()); |
16 | System.out.println("g:" + hp.getWeight()); |
17 | System.out.println("h:" + hp.getTitle()); |
18 | System.out.println("i:" + ttc.getPrice()); |
19 | System.out.println("j:" + ttc.getPrice()); |
20 |
|
21 | } // main method |
22 | } // class Q1 |
public class Q1_answer {
public static void main (String [] args) {
Book gp = new Book("Pratchett","Going Postal",799,0.15);
Song br = new Song("Lady Gaga","Bad Romance");
Product slts = new Song("Nirvana","Smells Like Teen Spirit",79);
Shippable hp = new Book("Rowling","Harry Potter & the Polymorphic Polyp",652,1.5);
// Shippable ttc = new Shippable("Dickens","Tale of Two Cities",999,1.5);
System.out.println("a:" + gp.getTitle());
System.out.println("b:" + br.getArtist());
System.out.println("c:" + br.getPrice());
System.out.println("d:" + slts.getPrice());
// System.out.println("e:" + slts.getTitle());
// System.out.println("f:" + hp.getPrice());
System.out.println("g:" + hp.getWeight());
// System.out.println("h:" + hp.getTitle());
//System.out.println("i:" + ttc.getPrice());
//System.out.println("j:" + ttc.getPrice());
}
}
Total points: ?
Product.java
|
Shippable.java
| ||||||||||||||||||||||||||||||||||||||||||||
Book.java
| |||||||||||||||||||||||||||||||||||||||||||||
Song.java
|