Chapter 4. Inheritance

Size: px
Start display at page:

Download "Chapter 4. Inheritance"

Transcription

1 Chapter 4 Inheritance CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science Dr. S. HAMMAMI

2 Objectives In In this this chapter you you will will learn How How inheritance promotes software reusability. The The notions of of superes and and subes. To To use use keyword extends to to create a that that inherits attributes and and behaviors from from another. To To use use access modifier to to give give sub methods access to to super members. To To access super members with with super. How How constructors are are used used in in inheritance hierarchies. The The methods of of Object, the the direct or or indirect super of of all all es in in Java. Java.

3 OUTLINE Introduction Defining Classes with with Inheritance Inheritance and and Member Accessibility Inheritance Hierarchy Declaring Subes Inheritance and and Constructors Examples

4 1. Introduction Inheritance is is the the sharing of of attributes and and methods among es. We We take take a (super), and and then then define other es based on on the the first first one one (sub). The The sub inherit all all the the attributes and and methods of of the the super, but but also also have have attributes and and methods of of their own. own. Software reusability Create new new from existing Absorb existing s data data and and behaviors Enhance with with new new capabilities Sub extends super Sub More More specialized group group of of objects objects Behaviors inherited from from super Can Can customize Additional behaviors

5 Introduction Class Class hierarchy hierarchy Direct Direct super super Inherited Inherited explicitly explicitly (one (one level level up up hierarchy) hierarchy) Indirect Indirect super super Inherited Inherited two two or or more more levels levels up up hierarchy hierarchy Single Single inheritance inheritance Inherits Inherits from from one one super super Multiple Multiple inheritance inheritance Inherits Inherits from from multiple multiple superes superes Java Java does does not not support support multiple multiple inheritance inheritance CommunityMember Faculty Student Staff Alumnus Administrator Teacher The The important important relationship relationship between between a a sub sub and and its itssuper superis is the the IS-A IS-A relationship. relationship. The The IS-A IS-A relationship relationship must must exist exist if if inheritance inheritance is is used used properly. properly.

6 2. Defining Classes with Inheritance Case Study 1 1 Suppose we we want implement a which has two attributes, id idand, and some basic get- and set- methods for for the the attributes. We want now define a PartTime ; this will inherit these attributes and methods, but can also have attributes (hourlypay) and methods of of its its own (calculateweeklypay).

7 An inheritance relationship using UML Defining Classes with Inheritance +id string + string +(in N string, in E string) +setname(in N string) +getnumber() string +getname() string -hourlypay PartTime +PartTime(in N string, in E string, in H ) +sethourlypay(in H ) +gethourlypay() +calculateweeklypay(in c )

8 3. Inheritance and Member Accessibility We We use use the the following visual representation of of inheritance to to illustrate data data member accessibility.

9 The Effect of Three Visibility Modifiers

10 Accessibility of Super from Sub Everything except the the members of of the the Super is is visible from from a method of of the the Sub Sub.

11 The Protected Modifier The The modifier Protected makes a data data member or or method visible and and accessible to to the the instances of of the the and and the the descendant es (subes). Public data data members and and methods are are accessible to to everyone. Private data data members and and methods are are accessible only only to to instances of of the the.

12 An inheritance relationship using UML The Protected Modifier #id string # string +(in N string, in E string) +setname(in N string) +getnumber() string +getname() string The symbol # indicates the members -hourlypay PartTime +PartTime(in N string, in E string, in H ) +sethourlypay(in H ) +gethourlypay() +calculateweeklypay(in c )

13 Case Study 2 Defining Classes with Inheritance Suppose we we want want implement a roster that that contains both both undergraduate and and graduate students. Each Each student s record will will contain his his or or her her, three three test test scores, and and the the final finalcourse grade. The The formula for for determining the the course grade is is different for for graduate students than than for for undergraduate students.

14 Modeling Two Types of Students There are are two two ways to to design the the es to to model undergraduate and and graduate students. We We can can define two two unrelated es, one one for for undergraduates and and one one for for graduates. We We can can model the the two two kinds of of students by by using es that that are arerelated in in an an inheritance hierarchy. Two Two es are are unrelated if if they they are are not not connected in in an an inheritance relationship.

15 Classes for the Class Roster For the Class Roster sample, we design three es Student UndergraduateStudent GraduateStudent The Student will incorporate behavior and data common to both UndergraduateStudent and GraduateStudent objects. The UndergraduateStudent and the GraduateStudent will each contain behaviors and data specific to their respective objects.

16 4. Inheritance Hierarchy

17 5. Declaring Subes Student //DATA MEMBERS ; [[]] test; test; Members to be inherited are designated as GraduateStudent extends Student //DATA MEMBERS extends allows GraduateStudent to inherit Student

18 Implementation of Case Study 1 number; number; ; ; ( ( N, N, E) E) number number N; N; E; E; setname( setname( N) N) N; N; getnumber() getnumber() number; number; getname() getname() ; ; PartTime PartTime extends extends hourlypay; hourlypay; PartTime( PartTime( N, N, E, E, H) H) number number N; N; E; E; hourlypay hourlypay H; H; sethourlypay( sethourlypay( H) H) hourlypay hourlypay H; H; gethourlypay() gethourlypay() hourlypay; hourlypay; calculateweeklypay( calculateweeklypay( c) c) hourlypay hourlypay * * c; c;

19 import import java.util.scanner; java.util.scanner; PartTimeTest PartTimeTest static static main([] main([] args) args) Scanner Scanner input input new new Scanner(System.in); Scanner(System.in); number, number, ; ; pay; pay; hours; hours; PartTime PartTime emp; emp; PartTime test program. // // get get the the details details from from the the user user System.out.pr System.out.pr ( ( Number? ); Number? ); number number input.next(); input.next(); System.out.pr System.out.pr ( ( Name? ); Name? ); input.next(); input.next(); System.out.pr System.out.pr ( Hourly ( Hourly pay? ); pay? ); pay pay input.double(); input.double(); System.out.pr System.out.pr ( Hours ( Hours worked worked this this week? ); week? ); hours hours input.int(); input.int(); // // create create a a new new part-time part-time employee employee emp emp new new PartTime PartTime (number, (number,,, pay); pay); //display //display employee s employee s details, details, including including the the weekly weekly pay pay System.out.prln(); System.out.prln(); System.out.prln(emp.getName()); System.out.prln(emp.getName()); System.out.prln(emp.getNumber()); System.out.prln(emp.getNumber()); System.out.prln(emp.calculateWeeklyPay(hours)); System.out.prln(emp.calculateWeeklyPay(hours));

20 Implementation of Case Study 2 Student Student /** /** The The number number of of tests tests this this student student took took */ */ final final static static NUM_OF_TESTS NUM_OF_TESTS 3; 3; ; ; [] [] test; test; coursegrade; coursegrade; Student( Student( ) ) this this ("No ("No Name"); Name"); Student( Student( studentname) studentname) studentname; studentname; test test new new [NUM_OF_TESTS]; [NUM_OF_TESTS]; coursegrade coursegrade "****"; "****"; setscore( setscore( s1, s1, s2, s2, s3) s3) test[0] test[0] s1; s1; test[1] test[1] s2; s2; test[2] test[2] s3; s3; getcoursegrade( getcoursegrade( ) ) coursegrade; coursegrade; getname( getname( ) ) ; ; gettestscore( gettestscore( testnumber) testnumber) test[testnumber-1]; test[testnumber-1]; setname( setname( newname) newname) newname; newname; Dr. Salah Hammami GraduateStudent GraduateStudent extends extends Student Student /** /** * * students. students. Pass Pass if if total total > > 80; 80; otherwise, otherwise, No No Pass. Pass. */ */ GraduateStudent( GraduateStudent( na) na) na; na; computecoursegrade() computecoursegrade() total total 0; 0; for for ( ( i i 0; 0; i i < < NUM_OF_TESTS; NUM_OF_TESTS; i++) i++) total total + + test[i]; test[i]; if if (total (total > > 80) 80) coursegrade coursegrade "Pass"; "Pass"; else else coursegrade coursegrade "No "No Pass"; Pass"; UndergraduateStudent UndergraduateStudent extends extends Student Student UndergraduateStudent( UndergraduateStudent( na) na) na; na; computecoursegrade() computecoursegrade() total total 0; 0; for for ( ( i i 0; 0; i i < < NUM_OF_TESTS; NUM_OF_TESTS; i++) i++) total total + + test[i]; test[i]; if if (total (total / / NUM_OF_TESTS NUM_OF_TESTS > > 70) 70) coursegrade coursegrade "Pass"; "Pass"; else else coursegrade coursegrade "No "No Pass"; Pass";

21 Student test program Since both undergraduate and graduate students are enrolled in a, It seems necessary for us to declare two separate arrays, one for graduate students and another for undergraduate students GraduateStudent gradstudent [20]; UndergraduateStudent undergradstudent [20]; StudentTest static main([] args) GraduateStudent [] gradstudent new GraduateStudent[20]; UndergraduateStudent [] undergradstudent new UndergraduateStudent[20]; gradstudent[0] new GraduateStudent("Ramzi"); gradstudent[0].setscore (20, 30, 50); gradstudent[0].computecoursegrade(); System.out.prln(gradStudent [0].getCourseGrade( )); undergradstudent[0] new UndergraduateStudent ("Ahmed"); undergradstudent[0].setscore (10, 17, 13); undergradstudent[0].computecoursegrade(); System.out.prln(undergradStudent[0].getCourseGrade( ));

22 6. Inheritance and Constructors Unlike members of a super, constructors of a super are not inherited by its subes. You must define a constructor for a or use the default constructor added by the compiler. A sub uses a constructor from the base to initialize all the data inherited from the base In order to invoke a constructor from the base, it uses a special syntax SubClass extends SuperClass //DATA MEMBERS. // Constructors super ( );.

23 Inheritance and Constructors A call to the base constructor can never use the of the base, but uses the keyword super instead A call to super must always be the first action taken in a constructor definition An instance variable cannot be used as an argument to super

24 Inheritance and Constructors number; number; ; ; ( ( N, N, E) E) number number N; N; E; E;.. Call to super constructor to initialize members inherited from super PartTime PartTime extends extends hourlypay; hourlypay; PartTime( N, E, H) number N; E; hourlypay H; PartTime PartTime extends extends hourlypay; hourlypay; PartTime( PartTime( N, N, E, E, H) H) super (N, E); hourlypay H;..

25 Case Study 3 Inheritance Hierarchy of Class BankAccount 1 Bank + string - string #accnumber string -balance +branchname string BankAcount +BankAccount(in accnum string, in nam string, in bal ) +getname() string +getaccnumber() string #getbalancer() #setbalance(in bal ) +deposite(in amount ) #debit(in amount ) -sum(in a, in b ) 1..* -erestrate +Savings(in accnum, in nam, in bal, in rate ) +getinterest() +addinterest() +setinterestrate(in rate ) +display() Savings

26 Implementation of Case Study 3 BankAccount BankAccount accnumber; accnumber; ; ; balance; balance; branchname; branchname; BankAccount( BankAccount( number, number, bal, bal, na na,, branna) branna) accnumber accnumber number; number; balance balance bal; bal; na; na; branchname branchname branna; branna; getaccnumber() getaccnumber() accnumber; accnumber; sum( sum( a, a, b) b) a+b; a+b; copy(bankaccount copy(bankaccount client) client) accnumber accnumber client.accnumber; client.accnumber; client.; client.; balanceclient.balance; balanceclient.balance; branchname branchname client.branchname; client.branchname; getbalance() getbalance() balance; balance; setbalance( setbalance( bl) bl) balance balance bl; bl; getname() getname() ; ; deposite( deposite( amount) amount) balancesum(balance balancesum(balance,, amount); amount); debit( debit( amount) amount) if if (amount (amount > > balance) balance) System.out.prln("Sorry.. System.out.prln("Sorry.. you you cannot cannot debit debit the"+amount); the"+amount); else Dr. else balancebalance Salah balancebalance - Hammami - amount; amount; Savings Savings extends extends BankAccount BankAccount erestrate; erestrate; Savings( Savings( number, number, bal, bal, na, na, bankna, bankna, rate) rate) super(number, super(number, bal, bal, na, na, bankna); bankna); erestrate erestrate rate; rate; setinterestrate( setinterestrate( rate) rate) erestrate erestrate rate; rate; getinterestrate() getinterestrate() erestrate; erestrate; addinterest() addinterest() erest erest (getbalance()* (getbalance()* ersetrate ersetrate )/100; )/100; setbalance(getbalance() setbalance(getbalance() + + erest); erest); display() display() System.out.prln(branchName+getName()+accNumber System.out.prln(branchName+getName()+accNumber +getbalance()); +getbalance());

27 Bank Bank ; ; BankAccount BankAccount [] [] customer; customer; nbc; nbc; Bank( Bank( size, size, na) na) customer customer new new BankAccount[size]; BankAccount[size]; na; na; nbc0; nbc0; boolean boolean addcustomers(bankaccount addcustomers(bankaccount client) client) if if (nbc (nbc < < customers.length) customers.length) customers[nbc++] customers[nbc++] client; client; true; true; else else false; false; BankAccountTest BankAccountTest static static main([] main([] args) args) Savings Savings savacc savacc new new Savings("112233", Savings("112233", , , "Ahmed", "Ahmed", "AlMalaz",10.0); "AlMalaz",10.0); savacc.display(); savacc.display(); savacc.debit(100.0); savacc.debit(100.0); //--- //--- object object savacc savacc inherites inherites method method debit debit from from the the superclass superclass BankAccount BankAccount savacc.display(); savacc.display(); savacc.addinterest(); savacc.addinterest(); //--- //--- object object savacc savacc utilizes utilizes method method addinterset addinterset from from subclass subclass savacc.display(); savacc.display(); savacc.deposite(10.5); savacc.deposite(10.5); //--- //--- object object savacc savacc inherites inherites method method deposit deposit from from the the superclass superclass BankAccount BankAccount savacc.display(); savacc.display(); Execution Execution of of the the program program BankAccountTest BankAccountTest Branch Branch Name Name AlMalaz AlMalaz Custemer Custemer Ahmed Ahmed Accunt Accunt namber namber Balance Balance Branch Branch Name Name AlMalaz AlMalaz Custemer Custemer Ahmed Ahmed Accunt Accunt namber namber Balance Balance Branch Branch Name Name AlMalaz AlMalaz Custemer Custemer Ahmed Ahmed Accunt Accunt namber namber Balance Balance Branch Branch Name Name AlMalaz AlMalaz Custemer Custemer Ahmed Ahmed Accunt Accunt namber namber Balance Balance

28 Case Study 4 # string #id string Vehiccle +Vehicle(in n string, in d string) +set(in s string, in x string) +display() +...(in...) Car -seatnb -year -ncel +Car(in n string, in d string, in s, in y, in size ) +display() +isfull() bool +copycar(in ca Car) +addelement(in el CarElements) bool +PriceCar() +...(in...) 1 * -code string -price CarElements +CarElements(in c string, in p ) +CarElement(in E CarElements) +display() +...(in...) * 1 -nbc KsuCars +KsuCars(in size ) +display() +isempty() bool +searchcar(in ce string) +getcar(in nm string) Car +AveragePrice(in y ) +...(in...) +remove(in s string) bool

29 Question Implement all the es with all their methods using the following descriptions. Description of the different es Class Vehicle The method display () displays the and the id. +.. (in..) if you need an other methods in this you can add it. Class CarElements The method display () displays the code and the price. +.. (in..) if you need an other methods in this you can add it. You can t add another constructor. Class Car seatnb Number of seats year Production year of car ncel number of CarElements object currently in an object of the Car. And other attribute(s) deduced from the UML diagram. display () Displays all the attributes of an object Car. addelement (CarElements el) This method receives a CarElements object and adds it to the Car object. pricecar() Returns the sum of the CarElements price in an object of the Car. +.. (in..) if youneed an other methods in this you can add it. Class KsuCars nbc number of Car currently in an object of the KsuCar. And other attribute(s) deduced from the UML diagram. display () Displays all the attributes of an object KsuCars. search ( ce) This method receives a representing the of a Car object and s the array index of the car object. getcar ( nm) This method receives a representing the id of a Car object and s the Car object if it s exist. removecar ( s) Removes a Car according to its. It will a value true if the operation has been completed successfully, or false if not. AveragePrice( y) Calculates the average price of all car in an object of KsuCars that produced after the year y. +.. (in..) if youneed an other methods in this you can add it.

Polymorphism. Chapter 4. CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science. Dr. S.

Polymorphism. Chapter 4. CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science. Dr. S. Chapter 4 Polymorphm CSC 113 King Saud University College Computer and Information Sciences Department Computer Science Objectives After you have read and studied th chapter, you should be able to Write

More information

Chapter 13. Inheritance and Polymorphism. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Chapter 13. Inheritance and Polymorphism. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Chapter 13 Inheritance and Polymorphism CS 180 Sunil Prabhakar Department of Computer Science Purdue University Introduction Inheritance and polymorphism are key concepts of Object Oriented Programming.

More information

Chapter 2: Relationship between. classes using UML. Dr. Safwan Qasem

Chapter 2: Relationship between. classes using UML. Dr. Safwan Qasem Chapter 2: Relationship between Dr. Safwan Qasem classes using UML King Saud University College of Computer and Information Sciences Computer Science Department What is UML? 2 The OMG (*) specification

More information

Announcements. Final exam. Course evaluations. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA

Announcements. Final exam. Course evaluations. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA Announcements Final exam Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA Course evaluations Wednesday November 28th Need volunteer to collect evaluations and deliver them to LWSN. 1 Chapter 13 Inheritance

More information

Chapter 10. Further Abstraction Techniques

Chapter 10. Further Abstraction Techniques Chapter 10 Further Abstraction Techniques In the previous chapter, we saw how Java checks the usage of methods. We also saw that if the method is not defined in the superclass, the compiler will not work.

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Recitation 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University Project 5 Due Wed, Oct. 22 at 10 pm. All questions on the class newsgroup. Make use of lab

More information

Inheritance (Deitel chapter 9)

Inheritance (Deitel chapter 9) Inheritance (Deitel chapter 9) 1 2 Plan Introduction Superclasses and Subclasses protected Members Constructors and Finalizers in Subclasses Software Engineering with Inheritance 3 Introduction Inheritance

More information

Chapter 7. Inheritance

Chapter 7. Inheritance Chapter 7 Inheritance Introduction to Inheritance Inheritance is one of the main techniques of objectoriented programming (OOP) Using this technique, a very general form of a class is first defined and

More information

Object Oriented Programming. CISC181 Introduction to Computer Science. Dr. McCoy. Lecture 27 December 8, What is a class? Extending a Hierarchy

Object Oriented Programming. CISC181 Introduction to Computer Science. Dr. McCoy. Lecture 27 December 8, What is a class? Extending a Hierarchy CISC181 Introduction to Computer Science Dr. McCoy Lecture 27 December 8, 2009 Object Oriented Programming Classes categorize entities that occur in applications. Class teacher captures commonalities of

More information

Programming in C# Inheritance and Polymorphism

Programming in C# Inheritance and Polymorphism Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014 Abstract Classes and Methods

More information

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC Topic 7: Inheritance Reading: JBD Sections 7.1-7.6 1 A Quick Review of Objects and Classes! An object is an abstraction that models some thing or process! Examples of objects:! Students, Teachers, Classes,

More information

Introduction to Inheritance

Introduction to Inheritance Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits

More information

Java Programming Lecture 7

Java Programming Lecture 7 Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 4&5: Inheritance Lecture Contents What is Inheritance? Super-class & sub class The object class Using extends keyword @override keyword

More information

This week. Tools we will use in making our Data Structure classes: Generic Types Inheritance Abstract Classes and Interfaces

This week. Tools we will use in making our Data Structure classes: Generic Types Inheritance Abstract Classes and Interfaces This week Tools we will use in making our Data Structure classes: Generic Types Inheritance Abstract Classes and Interfaces This is a lot of material but we'll be working with these tools the whole semester

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 17 Inheritance Overview Problem: Can we create bigger classes from smaller ones without having to repeat information? Subclasses: a class inherits

More information

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?

More information

Use the scantron sheet to enter the answer to questions (pages 1-6)

Use the scantron sheet to enter the answer to questions (pages 1-6) Use the scantron sheet to enter the answer to questions 1-100 (pages 1-6) Part I. Mark A for True, B for false. (1 point each) 1. Abstraction allow us to specify an object regardless of how the object

More information

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Introduction to Computers and Programming Languages CS 180 Sunil Prabhakar Department of Computer Science Purdue University 1 Objectives This week we will study: The notion of hardware and software Programming

More information

Inheritance Introduction. 9.1 Introduction 361

Inheritance Introduction. 9.1 Introduction 361 www.thestudycampus.com Inheritance 9.1 Introduction 9.2 Superclasses and Subclasses 9.3 protected Members 9.4 Relationship Between Superclasses and Subclasses 9.4.1 Creating and Using a CommissionEmployee

More information

Inheritance CSC9Y4. Inheritance

Inheritance CSC9Y4. Inheritance Inheritance CSC9Y4 1 Inheritance We start with a superclass from which a subclass can be derived. New attributes and methods can be defined in a subclass and existing methods re-defined. How do we know

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

A A B U n i v e r s i t y

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 10: I n h e r i t a n c e Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

More information

Inheritance Motivation

Inheritance Motivation Inheritance Inheritance Motivation Inheritance in Java is achieved through extending classes Inheritance enables: Code re-use Grouping similar code Flexibility to customize Inheritance Concepts Many real-life

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(b): Abstract classes & Polymorphism Lecture Contents 2 Abstract base classes Concrete classes Polymorphic processing Dr. Amal Khalifa,

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass? 1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type

More information

Inheritance and Subclasses

Inheritance and Subclasses Software and Programming I Inheritance and Subclasses Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Packages Inheritance Polymorphism Sections 9.1 9.4 slides are available at www.dcs.bbk.ac.uk/

More information

Inheritance. Chapter 7. Chapter 7 1

Inheritance. Chapter 7. Chapter 7 1 Inheritance Chapter 7 Chapter 7 1 Introduction to Inheritance Inheritance allows us to define a general class and then define more specialized classes simply by adding new details to the more general class

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Inheritance & Polymorphism

Inheritance & Polymorphism Inheritance & Polymorphism Procedural vs. object oriented Designing for Inheritance Test your Design Inheritance syntax **Practical ** Polymorphism Overloading methods Our First Example There will be shapes

More information

Chapter 9 - Object-Oriented Programming: Inheritance

Chapter 9 - Object-Oriented Programming: Inheritance Chapter 9 - Object-Oriented Programming: Inheritance 9.1 Introduction 9.2 Superclasses and Subclasses 9.3 protected Members 9.4 Relationship between Superclasses and Subclasses 9.5 Case Study: Three-Level

More information

CIS 110: Introduction to computer programming

CIS 110: Introduction to computer programming CIS 110: Introduction to computer programming Lecture 25 Inheritance and polymorphism ( 9) 12/3/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Inheritance Polymorphism Interfaces 12/3/2011

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Inheritance Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All Inheritance A form of software reuse in which a new class is created by absorbing an existing class s members and enriching them with

More information

Objects and Classes. Lecture 10 of TDA 540 (Objektorienterad Programmering) Chalmers University of Technology Gothenburg University Fall 2017

Objects and Classes. Lecture 10 of TDA 540 (Objektorienterad Programmering) Chalmers University of Technology Gothenburg University Fall 2017 Objects and Classes Lecture 10 of TDA 540 (Objektorienterad Programmering) Carlo A. Furia Alex Gerdes Chalmers University of Technology Gothenburg University Fall 2017 All labs have been published Descriptions

More information

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini 24. Inheritance Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Superclasses and Subclasses Inheritance

More information

Inheritance -- Introduction

Inheritance -- Introduction Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept

More information

9/10/2018 Programming Data Structures Inheritance

9/10/2018 Programming Data Structures Inheritance 9/10/2018 Programming Data Structures Inheritance 1 Email me if the office door is closed 2 Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the

More information

CSE 113 A. Announcements - Lab

CSE 113 A. Announcements - Lab CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure

More information

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 22. Inheritance Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Inheritance Object-oriented programming

More information

BBM 102 Introduction to Programming II Spring Inheritance

BBM 102 Introduction to Programming II Spring Inheritance BBM 102 Introduction to Programming II Spring 2018 Inheritance 1 Today Inheritance Notion of subclasses and superclasses protected members UML Class Diagrams for inheritance 2 Inheritance A form of software

More information

Inheritance (continued) Inheritance

Inheritance (continued) Inheritance Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses

More information

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics

More information

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED EXERCISE 11.1 1. static public final int DEFAULT_NUM_SCORES = 3; 2. Java allocates a separate set of memory cells in each instance

More information

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College CISC 3115 TY3 C09a: Inheritance Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/20/2018 CUNY Brooklyn College 1 Outline Inheritance Superclass/supertype, subclass/subtype

More information

Object Oriented Relationships

Object Oriented Relationships Lecture 3 Object Oriented Relationships Group home page: http://groups.yahoo.com/group/java CS244/ 2 Object Oriented Relationships Object oriented programs usually consisted of a number of classes Only

More information

C# Programming for Developers Course Labs Contents

C# Programming for Developers Course Labs Contents C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring

More information

1.00 Lecture 13. Inheritance

1.00 Lecture 13. Inheritance 1.00 Lecture 13 Inheritance Reading for next time: Big Java: sections 10.5-10.6 Inheritance Inheritance allows you to write new classes based on existing (super or base) classes Inherit super class methods

More information

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

Inheritance: Definition

Inheritance: Definition Inheritance 1 Inheritance: Definition inheritance: a parent-child relationship between classes allows sharing of the behavior of the parent class into its child classes one of the major benefits of object-oriented

More information

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. CMPUT 102: Inheritance Dr. Osmar R. Zaïane. University of Alberta 4

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. CMPUT 102: Inheritance Dr. Osmar R. Zaïane. University of Alberta 4 Structural Programming and Data Structures Winter 2000 CMPUT 102: Inheritance Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection Repetition

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Week 9 Lab - Use of Classes and Inheritance 8th March 2018 SP1-Lab9-2018.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab 9: Objectives Exercise 1 Student & StudentTest classes 1.

More information

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,

More information

EXAM Computer Science 1 Part 1

EXAM Computer Science 1 Part 1 Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

Intro to Computer Science 2. Inheritance

Intro to Computer Science 2. Inheritance Intro to Computer Science 2 Inheritance Admin Questions? Quizzes Midterm Exam Announcement Inheritance Inheritance Specializing a class Inheritance Just as In science we have inheritance and specialization

More information

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive

More information

Lecture 18 CSE11 Fall 2013 Inheritance

Lecture 18 CSE11 Fall 2013 Inheritance Lecture 18 CSE11 Fall 2013 Inheritance What is Inheritance? Inheritance allows a software developer to derive a new class from an existing one write code once, use many times (code reuse) Specialization

More information

ASSIGNMENT NO 13. Objectives: To learn and understand concept of Inheritance in Java

ASSIGNMENT NO 13. Objectives: To learn and understand concept of Inheritance in Java Write a program in Java to create a player class. Inherit the classes Cricket_player, Football_player and Hockey_player from player class. The objective of this assignment is to learn the concepts of inheritance

More information

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

The software crisis. code reuse: The practice of writing program code once and using it in many contexts. Inheritance The software crisis software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues:

More information

Object-oriented basics. Object Class vs object Inheritance Overloading Interface

Object-oriented basics. Object Class vs object Inheritance Overloading Interface Object-oriented basics Object Class vs object Inheritance Overloading Interface 1 The object concept Object Encapsulation abstraction Entity with state and behaviour state -> variables behaviour -> methods

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. All Rights Reserved. 1 Inheritance is a form of software reuse in which you create a class that absorbs an existing class s data and behaviors

More information

Inheritance (Outsource: )

Inheritance (Outsource: ) (Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,

More information

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: has a CSC Employee. Supervisor CSC 143 Object & Class Relationships Inheritance Reading: Ch. 10, 11 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog

More information

Big software. code reuse: The practice of writing program code once and using it in many contexts.

Big software. code reuse: The practice of writing program code once and using it in many contexts. Inheritance Big software software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues: getting

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

More information

Object-Oriented Programming (Java)

Object-Oriented Programming (Java) Object-Oriented Programming (Java) Topics Covered Today 2.1 Implementing Classes 2.1.1 Defining Classes 2.1.2 Inheritance 2.1.3 Method equals and Method tostring 2 Define Classes class classname extends

More information

Encapsulation. Mason Vail Boise State University Computer Science

Encapsulation. Mason Vail Boise State University Computer Science Encapsulation Mason Vail Boise State University Computer Science Pillars of Object-Oriented Programming Encapsulation Inheritance Polymorphism Abstraction (sometimes) Object Identity Data (variables) make

More information

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: has a CSE143 Sp Student. CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

CSC Inheritance. Fall 2009

CSC Inheritance. Fall 2009 CSC 111 - Inheritance Fall 2009 Object Oriented Programming: Inheritance Within object oriented programming, Inheritance is defined as: a mechanism for extending classes by adding variables and methods

More information

Practice problem on defining and using Class types. Part 4.

Practice problem on defining and using Class types. Part 4. CS180 Programming Fundamentals Practice problem on defining and using Class types. Part 4. Implementing object associations: Applications typically consist of collections of objects of different related

More information

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class. Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone

More information

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name: CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : In mathematics,

More information

CST141--Inheritance 2

CST141--Inheritance 2 - employeeid - hoursworked - checknumber payrate -+ employeeid setchecknumber() -+ hoursworked setemployeeid() -+ payrate sethoursworked() ed-oriented and Inheritance + setchecknumber() setpayrate() CST141

More information

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. Inheritance Hierarchy. The Idea Behind Inheritance

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. Inheritance Hierarchy. The Idea Behind Inheritance Structural Programming and Data Structures Winter 2000 CMPUT 102: Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection Repetition Vectors

More information

CH. 2 OBJECT-ORIENTED PROGRAMMING

CH. 2 OBJECT-ORIENTED PROGRAMMING CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 11: Inheritance and Polymorphism Part 1 Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad

More information

25. Generic Programming

25. Generic Programming 25. Generic Programming Java Fall 2009 Instructor: Dr. Masoud Yaghini Generic Programming Outline Polymorphism and Generic Programming Casting Objects and the instanceof Operator The protected Data and

More information

Inheritance. Reference Text: Chapter11, Big C++

Inheritance. Reference Text: Chapter11, Big C++ Inheritance pm_jat@daiict.ac.in Reference Text: Chapter11, Big C++ Class relationships Recall your Lab05; You had a Point class, you had a curve class, what was a relationship between? Curve has points?

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and

More information

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor CSE 143 Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog Dog

More information

Classes and Inheritance Extending Classes, Chapter 5.2

Classes and Inheritance Extending Classes, Chapter 5.2 Classes and Inheritance Extending Classes, Chapter 5.2 Dr. Yvon Feaster Inheritance Inheritance defines a relationship among classes. Key words often associated with inheritance are extend and implements.

More information

Introduction to Objects. James Brucker

Introduction to Objects. James Brucker Introduction to Objects James Brucker What is an Object? An object is a program element that encapsulates both data and behavior. An object contains both data and methods that operate on the data. Objects

More information

Lab Exercise 1. Objectives: Part 1. Introduction

Lab Exercise 1. Objectives: Part 1. Introduction Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

OO design. Classes, Responsibilities, Collaborations (CRC) 13/9/1999 COSC

OO design. Classes, Responsibilities, Collaborations (CRC) 13/9/1999 COSC OO design Classes, Responsibilities, Collaborations (CRC) 1 bank accounts the system to be modelled: bank accounts with differing fee structures purpose: evaluate different account types with respect to

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 4(b): Inheritance & Polymorphism Lecture Contents What is Inheritance? Super-class & sub class The object class Using extends keyword

More information

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 PROGRAMMING FOR NON-SPECIALISTS CMP-5020B Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

Darrell Bethea June 6, 2011

Darrell Bethea June 6, 2011 Darrell Bethea June 6, 2011 Program 4 due Friday Testing/debugging help online Final exam Comprehensive Monday, 6/13, 8-11 AM SN014 2 3 Inheritance 4 We have discussed before how classes of objects can

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

More On inheritance. What you can do in subclass regarding methods:

More On inheritance. What you can do in subclass regarding methods: More On inheritance What you can do in subclass regarding methods: The inherited methods can be used directly as they are. You can write a new static method in the subclass that has the same signature

More information

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information