Presentation is loading. Please wait.

Presentation is loading. Please wait.

Today’s lecture Review chapter 5 go over exercises.

Similar presentations


Presentation on theme: "Today’s lecture Review chapter 5 go over exercises."— Presentation transcript:

1

2 Today’s lecture Review chapter 5 go over exercises

3 Classes and Objects What is a class? (What do we place in a class?) What is an object? (where do we create them?) How do we create a class? How do we create an object? How do we use an object?

4 Object Uniqueness Multiple objects of one type can be created that are distinct. Each occupies a separate spot in memory. // create many objects Knapsack knap1 = new Knapsack(); Knapsack knap2 = new Knapsack(); knap1.size = 5; knap2.size = 8; System.out.println(knap1.size); System.out.println(knap2.size);

5 Objects are values Objects are just values of a particular type (the given class type). "Every expression has a type": class-definitions are types too! Object-yielding expressions (yield a value of a reference type): constructor calls methods with a return type that is a class Nothing Special… Arrays of a reference type work just like arrays of primitive types. Expressions involving reference types are still just expressions. Variables can store reference types.

6 Default Constructors Default Constructor: Java provides a default constructor definition when none is present in a class: all instance variables get default values: primitive types get 0, 0.0, false, or ' ' ; reference types (class types) get the null value. null is a special value: it represents a value of any reference type but has no actual reference value (no instance variables, no methods). Attempting to use null like an actual object is a very common run-time error.

7 Let’s go over the exercises

8 Questions?


Download ppt "Today’s lecture Review chapter 5 go over exercises."

Similar presentations


Ads by Google