MIST 4600 Final
What is output? import java.util.ArrayList; public class SimpleCar { @Override public String toString(){ return "I drive fast"; } public static void main(String[] args){ ArrayList <Object> myStuff; myStuff = new ArrayList<Object>(); myStuff.add(new String("Greetings")); myStuff.add(new Object()); myStuff.add(new SimpleCar()); for(Object item : myStuff){System.out.println(item.toString());}}}
Greetings java.lang.Object@169b I drive fast
___ refers to determining which program behavior to execute depending on data types.
Polymorphism
How many objects are created? Dog labrador = new Dog(); Dog poodle; Dog beagle = new Dog(); poodle = beagle;
2
public class MyEvenNumbers { public static void main(String[] args) { HashSet<Integer> evenNumbers = new HashSet<Integer>(); evenNumbers.add(2); evenNumbers.add(4); evenNumbers.add(6); evenNumbers.add(2); System.out.println(evenNumbers.size());}}
3
How many references are declared? Dog labrador = new Dog(); Dog poodle; Dog beagle = new Dog(); poodle = beagle; poodle = labrador;
3?
What is output? Item jar = new Item(); Item ball = new Item(); System.out.println(Item.count); public class Item{ public static int count = 1; public Item(){ count++; }}
3???
What is the size of groceryList after the code segment? ArrayList<String> groceryList; groceryList = new ArrayList<String>(); groceryList.add("Bread"); groceryList.add("Apples"); groceryList.add("Grape Jelly"); groceryList.add("Peanut Butter"); groceryList.set(1, "Frozen Pizza");
4 (arraylist after the code executed is [Bread, Frozen Pizza, Grape Jelly, Peanut Butter], whose size is 4.)
What is output? ArrayList<Integer> numList = new ArrayList<Integer>(); int count; for(count = 1; count < 10; ++count) {numList.add(count); } System.out.println(numList.get(4));
5
What is output? public class StudentGrade {public static void main (String[] args) { HashMap<Character, String> studentGrade = new HashMap<Character, String>(); studentGrade.put('A', "90-100%"); studentGrade.put('B', "80-89%"); studentGrade.put('C', "70-79%"); studentGrade.put('D', "60-69%"); studentGrade.put('F', "< 60%"); System.out.println(studentGrade.get('C'));}}
70-79%
For HashSet<Integer> employeeCodes = new HashSet<Integer>(); , which statement will populate the set?
employeeCodes.add(1201);
Given HashMap<String, Float> studentList, what is output?studentList.put("Aron", 98.89);studentList.put("Ben", 73.59);studentList.clear();System.out.println(studentList.containsKey("Ben"));
false
Which method has been overridden?public class Vehicle { public void setID(int pID) { ... } public String getName(){ ... } } public class Plane extends Vehicle { public Plane(){ ... } public void setID(int pID1, int pID2){ ... } public void getName(String name){ ... } public String getName(){ ... }}
getName()
Which replaces "Apples" with "Bananas"? ArrayList<String> groceryList; groceryList = new ArrayList<String>(); groceryList.add("Bread"); groceryList.add("Apples"); groceryList.add("Grape Jelly");
groceryList.set(1, "Bananas");
Which accesses the number of elements in groceryList? ArrayList <String> groceryList; groceryList = new ArrayList<String>();
groceryList.size( )
A reference variable stores the _____ of the object to which it refers.
memory location Reference variables can be considered as alternative names given to the existing variables. These variables point to the original variable. It contains the memory location of the original value.
The @Override annotation is ___.
optional and placed above an overridden method in the derived class
A derived class method with the same name, parameters, and return type as a base class method is said to _____ the base class's method.
override
Declaring a member as ____ in the base class provides access to that member in the derived classes but not to anyone else.
protected
Select the default constructor signature for a Student class.
public Student( )
Select mutator XXX to set the temperature. public class WeatherData { private double myTemp; XXX}
public void setTemp(double temp) { myTemp = temp;}
Which members of base class Players are inherited by SoccerPlayers ? public class Players { public void setName(String newName) { ...} public void setAge(int newAge) { ... } public void printDetails() { ... } private String playerName; private int playerAge; }; public class SoccerPlayers extends Players { public void setDetails(String newName) { ... } public String getLeague() { ... } private String teamName; };
x only setName, setAge, printDetails
What is the value of fordFusion's odometer at the end of main( )? public class SimpleCar { private int odometer; public SimpleCar() { odometer = 0; } public SimpleCar(int miles) { odometer = miles; } public void drive(int miles) { odometer = odometer + miles; } public static void main(String[] args) { SimpleCar fordFusion = new SimpleCar(); SimpleCar hondaAccord = new SimpleCar(30); fordFusion.drive(100); fordFusion.drive(20);}}
120
Which is true? public class Vehicle { protected String name; private int ID; } public class Car extends Vehicle {protected int miles;}
Car members have access to Vehicle name
Which calls increment() from outside class Inventory? public class Inventory{public static void increment(){...};}
Inventory.increment();
In the following creation of a HashMap, what does String represent? HashMap<String, Integer> schoolIDs = new HashMap<String, Integer>();
Key type
What is output? public class KitchenAppliance { protected String appName; protected String appUse; public void setDetails(String name, String use) { appName = name; appUse = use; } public void printDetails() { System.out.println("Name: " + appName); System.out.println("Use: " + appUse); } } public class Blender extends KitchenAppliance { private double appPrice; void setPrice(double price) { appPrice = price; } public void printDetails (){ super.printDetails(); System.out.println("Price: $" + appPrice); } public static void main(String [] args) { Blender mxCompany = new Blender(); mxCompany.setDetails("Blender", "blends food"); mxCompany.setPrice(145.99); mxCompany.printDetails();}}
Name: MyMixer Use: blend food Price: $145.99 Price: $145.99