







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








public class Message { private String text; private int priority; public Message(String theText, int thePriority) { text = theText; priority = thePriority; } public void setMessage(String newText, int newPriority) { text = newText; priority = newPriority; } public static void passing(Message good, Message bad, double k) { Message temp = good; temp.setMessage("SUMMER", 100); bad = null ; good.setMessage("LAST", 200); k = 200; // END POINT (Before returning from method) } public static void main(String[] args) { double max = 79.0; Message winter = new Message("WINTER", 30); Message fall = new Message("FALL", 40); passing(winter, fall, max); } }
public class City { public String name; private int population; public static int totalCities = 100; public static final int maxBudget = 20; public City(String theName, int thePopulation) { name = theName; population = thePopulation; } public void display() { System.out.println("Name: " + name); System.out.println("Population: " + population); } }
a. City.name = null ; b. City.population = 10; c. City.totalCities = 100; d. City c1 = City(); e. City c2 = new City(); f. City c3 = new City("Washington", 3); g. City.display(); h. City c4 = new City( new City()); i. name = "Washington"; j. population = 10; k. City.maxBudget = 30; l. totalCities = 20; m. new City().display();
public static void main(String[] args) { Rectangle r1 = new Rectangle(2,3); Rectangle r2 = new Rectangle(7,5); System.out.println(r1); System.out.println("Area: " + r1.area()); System.out.println(r1.merge(r2)); Rectangle[] allRects = new Rectangle[2]; allRects[0] = r1; allRects[1] = r2; System.out.println("Total Area: " + Rectangle.totalArea(allRects)); }
Length: 2.0 Width: 3. Area: 6. Length: 9.0 Width: 8. Total Area: 41.
public static void main(String[] args) { Utilities util = new Utilities(); int [] values = {10, 1, 8, 13, 2, 15, 18}; System.out.println("Count: " + util.count(values, 8)); int [] result = util.filter(values, 8); for ( int i=0; i<result.length; i++) { System.out.print(result[i] + " "); } }
Count: 3 1 8 2