1.[5] Name 8 Java primitive types .
The 8 primitives types are:
byte, short, int, long, float, double
char
boolean
2.[5] In order for the public class MyClass to successfully
compile, which of the following must be true?
a) MyClass must have a correctly formed main() method.
b) MyClass must be defined in the file MyClass.java
c) MyClass must be defined in the MyClass package.
d) MyClass must be imported
b) MyClass must be defined in the file MyClass.java
Note that MyClass does not need to have a "main()" method.
3.[5] Java provides two ways to compare if 2 items are the same : == and the .equals() method. State the criterion you use to decide which of these to use?
== is used when comparing values of primitives like int and double. However, == on objects does not compare their values, it compares their addresses.
The equals() method is used to compare objects' values. We can override the equals()
method to provide extra functionality to the comparison operation.
4.[2] Which is the class at the top of the Java platform inheritance hierarchy?
All classes in Java inherit from java.lang.Object class
.
5.[3] Look up the documentation for the Button class from the Sun's website and list the names of all the methods that are inherited by the ToggleButton class in the book. The ToggleButton class is discussed on page 201 of the text book(code in fig 4-21).
The methods inherited from class Button are:
addActionListener(ActionListener l)
addNotify() getAccessibleContext()
getActionCommand()
getLabel()
getListeners(Class listenerType)
paramString()
processActionEvent(ActionEvent e)
processEvent(AWTEvent e)
removeActionListener(ActionListener
l)
setActionCommand(String command)
setLabel(String label)