Lecture 21b

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Lecture 21b as PDF for free.

More details

  • Words: 392
  • Pages: 11
1

8 Classes and Objects: A Deeper Look  2005 Pearson Education, Inc. All rights reserved.

2

OBJECTIVES In this chapter you will learn: ƒ Encapsulation and data hiding. ƒ The notions of data abstraction and abstract data types (ADTs). ƒ To use keyword this. ƒ To use static variables and methods. ƒ To import static members of a class. ƒ To use the enum type to create sets of constants with unique identifiers. ƒ How to declare enum constants with parameters.

 2005 Pearson Education, Inc. All rights reserved.

3

8.2 Time Class Case Study •public services (or public interface) – public methods available for a client to use

• If a class does not define a constructor the compiler will provide a default constructor • Instance variables – Can be initialized when they are declared or in a constructor – Should maintain consistent (valid) values

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

4

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

5

8.2 Time Class Case Study (Cont.) •String method format – Similar to printf except it returns a formatted string instead of displaying it in a command window

•new implicitly invokes Time1’s default constructor since Time1 does not declare any constructors

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

6

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

7

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

8

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

8.4 Referring to the Current Object’s Members with the this Reference

9

• The this reference – Non-static methods implicitly use this when referring to the object’s instance variables and other methods – Can be used to access instance variables when they are shadowed by local variables or method parameters

• A .java file can contain more than one class – But only one class in each .java file can be public

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

10

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

11

IT114

Winter 2007

R.B. Lenin

DA-IICT

 2005 Pearson Education, Inc. All rights reserved.

Related Documents

Lecture 21b
November 2019 3
21b Tp6
May 2020 5
Numbers 21b
December 2019 3
Deuteronomy 21b-22
June 2020 2
Lecture
October 2019 41
Lecture
November 2019 30