Unit 2 Lesson 1-4 notes
What will be printed by the following code? System.out.print("All\nright\tnow");
All right now
______ data types can hold several pieces of data and have methods to work on that data.
Class
______ data types hold the memory address of where the data is stored.
Class
What is stored in w1 by the following? (with the word banana) w1 = w3.substring(2);
nana
A special value that can be assigned to an object that has no value:
null
What is the output? (with the word banana) System.out.println(w3.compareTo("fruit"));
-4
To output: Nums: 12 13 14 15 You would need to use what escape sequence in the blank: System.out.print("Nums: 12 13 14______15");
/t
Which of the following code segments correctly declare a String s and gives it a value of "fortran"?
1. String s; s = "fortran"; 2. String s = "fortran"; 3. String s = ("fortran");
Which of the following are true about class data types?
1. a programmer can them 2. holds more than one piece of data at a time 3. has built in methods (tools)
Consider the following code: int x = 9; int y = 8; System.out.println(x + y); What is output?
17
Which one of the following sentences is true?
A String is a class data type so a String variable holds a reference to a location in memory
Which of the following best describes the relationship between a class and an object?
A class is a template or blueprint from which an object can be created.
Consider the following code: String a = "CSA"; String b = a;a = "AP"; System.out.println(a + " " + b); What is printed when the code is run? Hint: Remember Strings are immutable.
AP CSA
Consider the following code: int x = 56; int y = 30; System.out.print("Answer: " + x + y); This code outputs: Answer: 86 True or false?
False
______ data types hold only one piece of information at a time.
Primitive
Which code shows us creating an object of data type Scanner class and storing it with a variable named X ?
Scanner X = new Scanner(System.in);
Examples of classes
String and Scanner
Which of the following would set the String variable firstName to be completely empty (i.e. not even storing a memory address)?
String firstName = null;
Which of the following correctly declares a new variable which can be used to point to an object of the String class type?
String str;
Which of the following commands will print the output below? \/ ''
System.out.print("\\/\n\'\'")
Consider the following code: System.out.println("Answer: " + (2 + 5)); This code outputs: Answer: 7 True or false?
True
Which of the following symbols need an escape character to be output in a System.out.print statement?
\
What is stored in w1 by the following? (with the word banana) w1 = w3.substring(1,3);
an