ptg7068951
Workshop 135
Q&A
Q. Can classes inherit from more than one class?
A. It’s possiblewith some programming languages (such as C++),but not
Java. Multiple inheritance is a powerful feature,but it also makes OOP a
bit harder to learn and use. Java’s developers decided to limit inheri-
tance to one superclass for any class,although a class can have numer-
ous subclasses. One way to compensate for this limitation is to inherit
methods from a special type of class called an interface. You learn more
about interfaces during Hour 19,“Creating a Threaded Program.”
Q. When would you want to create a method that isn’t public?
A. The main time you would not want to make a method available to other
programs is when the method is strictly for the use of one program
you’re writing. If you’re creating a game program and your
shootRayGun()method is highly specific to the game you’re writing,it
could be a private method. To keep a method from being public, leave
off the publicstatement in front of the method’s name.
Q. Why is it possible to use charvalues as if they were intvalues?
A. A character can be used as an intvariable because each character
has a corresponding numeric code that represents its position in the
character set. If you have a variable named kwith the value 67,the
cast(char) kproduces the character value ‘C’because the numeric
code associated with a capital C is 67,according to the ASCII character
set. The ASCII character set is part of the Unicode character standard
adopted by the Java language.
Q. Does Tabasco hot sauce spoil?
A. No it doesn’t,though if you keep an opened bottle around for several
years it will change color. The ingredients of vinegar,red pepper,and
salt are an extremely inhospitable environment for bacterial growth.
McIlhenny Company,the makers of Tabasco,say the original brand has
a shelf life of five years. Other versions have a shelf life from 18
months to three years.
As a huge fan of the product,I find it hard to believe anyone is keeping
a bottle of Tabasco around long enough to ask this question.
Workshop
The following questions test your knowledge of objects and the programs that
use them.