9781439035665 ppt ch07_passing_primitivetypeasobjects

26
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 Passing Primitive Types As Objects

Transcript of 9781439035665 ppt ch07_passing_primitivetypeasobjects

Page 1: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Chapter 7Passing Primitive Types As Objects

Page 2: 9781439035665 ppt ch07_passing_primitivetypeasobjects

• Java provides the classes Integer, Double, Character, Long, and Float so that the values of the primitive data types can be treated as objects

• These classes have limitations

• You can create objects of the type, say Integer, to store int values, but you cannot change the values stored in the objects

• You can create objects of type IntClass and/or change the values of the objects

Java Programming: From Problem Analysis to Program Design, 4e

Page 3: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 4: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 5: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 6: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 7: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 8: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Sample Run: In this sample run, the user input is shadedLine 1: Based on the course score, this program computes the course grade.Line 5: Enter the course score: 90.50Line 9: The course score is 90.5Line 10: Your grade for the course is A

Page 9: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 10: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 11: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 12: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 13: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 14: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 15: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

num1 = 10; //Line 5

Page 16: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

num1 = 10; //Line 5num2.setNum(15); //Line 6ch = 'A'; //Line 7str = new StringBuffer("Sunny"); //Line 8

Page 17: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 18: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

num = b.getNum(); //Line 14

Page 19: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 20: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 21: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 22: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 23: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 24: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 25: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e

Page 26: 9781439035665 ppt ch07_passing_primitivetypeasobjects

Java Programming: From Problem Analysis to Program Design, 4e