Programming and Problem Solving with Java

(やまだぃちぅ) #1
93

11.A variable of the classStringcan be assigned to a variable of typechar. (True or
False?)

12.A literal string can be assigned to a variable of the class String. (True or False?)


13.What is the difference between the literal string "computer"and the identifier
computer?


14.What is output by the following code segment? (All variables are of the class
String.
street = "Elm St.";
address = "1425B";
city = "Amaryllis";
state = "Iowa";
streetAddress = address +" "+ street;
System.out.println(streetAddress);
System.out.println(city);
System.out.println(", "+ state);


15.Correct the following program so that it displays "Martin Luther King Jr."


// This application is full of errors
classLotsOfErrors;
{
void main (string args[]);
{
constantString FIRST : Martin";
constantString MID : "Luther;
constantString LAST : King

String name;
characterinitial;
name = Martin + Luther + King;
initial = MID;
LAST = "King Jr.";
System.out.println('Name = '+ name));
System.out.println(mid
}

16.What does a constructor do?


17.Name three kinds of methods other than a constructor.


18.How do you invoke an instance method?


19.Name two instance methods associated with the System.outobject.

Free download pdf