Questions Exam With Complete Solutions
Graded A+
QUESTIONS AND ANSWERS
How to identify variable and methods? ANSWER -camelCase
How to identify classes? ANSWER -PascalCase
Is double the same as Double? ANSWER -No
What are the members of the Object class? ANSWER -public boolean equals (Object obj);
public String toString( );
How are String objects made using the reserve word "new"? ANSWER -String str = new
String("word");
How are String objects created without using the reserve word "new"? ANSWER -String
str = "word";
What are the two ways to write an output statement and how are they different?
ANSWER -System.out.print( ); - prints the statement and does not move the cursor
System.out.println( ); - prints the statement and then moves the cursor
When is a "+" an addition operator? ANSWER -When it does not follow a String object.
When is a "+" a concatenation operator? ANSWER -When it is preceded by a String
object.
, What does \" output? ANSWER -One double quotation ( " ).
What does \\ output? ANSWER -One backwards slash ( \ ).
What does \n do? ANSWER -Inserts a new line (a line break).
What is == when comparing String objects? ANSWER -It checks to see if two objects
point to the same memory location.
What is .equals( ) when comparing String objects? ANSWER -It checks to see if two
objects hold the same values.
What are the two types of variables? ANSWER -Primitive data types
Object Reference
What are the four primitive data types and what are their default values? ANSWER -
double - 0.0
int - 0
char- null
boolean- false
What are the method headers for the String methods? ANSWER -public int
compareTo(String str);
public int length( );
public int indexOf(String str);
public int substring(int begin);
public int substring(int begin, int end);
public boolean equals (Object obj);
public String toString( ) ;
What are the method calls for the String methods? ANSWER -word1.compareTo(word2);
word1.length( );