1 introduction to computer science for majors ii cpsc 233, winter 2013 cpsc 233, winter 2013...

10
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

Upload: kellie-gordon

Post on 20-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

CPSC 233, winter 20131

Introduction to Computer Science for

Majors II

CPSC 233, Winter 2013

Tutorial 14, Mar 27/28, 2013

Page 2: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

2

OutlineReview

Quiz

CPSC 233, winter 2013

Page 3: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

Key ConceptsAdvanced Java

Copy constructorPass by valuePass by referenceStatic members

InheritancePrivate, protected, publicMember inheritanceMethod overriding v.s method overloading Invoking of the constructors

CPSC 233, winter 2013 2

Page 4: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

4CPSC 233, winter 2013

Page 5: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

5CPSC 233, winter 2013

Page 6: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

6CPSC 233, winter 2013

• Is the toString() method considered overloading or overriding?• Is the definition of the method println(), println(String),

println(int), etc… considered overloading or overriding?• If you have multiple constructors in the same class with

different arguments, is it considered overloading or overriding?

Page 7: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

7

Constructor InvokingThe non-argument constructor automatically calls the

super class constructor which calls its super class constructor up to the class object constructor

If you want to call a constructor in the super class use:super(……)

CPSC 233, winter 2013

Page 8: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

8

UML Diagram (source code in practice1/)

Parent

- secret:int# familySecret:int+ num:int+ Parent()+ method()+ update()+ toString():String

Child1

- num1:int# num2:int+ count:int+ Child1()+ method()+ toString():String

Child2

- num1:int# num2:int+ Child2()+ Child2(obj:Child2)+ update()+ update(n:int)+ update(obj:Child1)+ toString():String

Answer the following questions based on the given program

What are the data members that Child1 inherits from the superclass?

What are the methods that Child1 inherits from the superclass?

Identify method overriding in this program

Identify method overloading in this program

What is the output of the program (see Driver.java)?

Page 9: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

9

UML Diagram (source code in practice2/)

GrandParent

- secret:int# familySecret:int+ num:int+ GrandParent()+ method()+ update()+ toString():String

Child1

- num1:int+ count:int+ Child1()+ Child1(obj:Child1)+ method()+ update(obj:Child1)+ toString():String

Parent

- num1:int# num2:int+ Parent()+ update()+ update(n:int)+ toString():String

Answer the following questions based on the given program

What are the data members that Child1 inherits from the superclass(es)?

What are the methods that Child1 inherits from the superclass(es)?

What are the data members that Parent inherits from the superclass?

What are the methods that Parent inherits from the superclass?

Identify method overriding in this program

Identify method overloading in this program

What is the output of the program (see Driver.java)?

Page 10: 1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

10

OutlineReview

Quiz

CPSC 233, winter 2013