Lesson 35..Inheritance

Size: px
Start display at page:

Download "Lesson 35..Inheritance"

Transcription

1 Lesson 35..Inheritance 35-1 Within a new project we will create three classes BankAccount, SavingsAccount, and Tester. First, the BankAccount class: public class BankAccount public BankAccount(double amt) //Constructor balance = amt; public double getbalance( ) // You supply code here that returns the state variable, balance. public void deposit(double d) //You supply code here that adds d to balance. public void withdraw(double d) //You supply code here that subtracts d from balance. private double balance; Subclass and Superclass: This BankAccount class will be known as our Superclass. We will now create a SavingsAccount class that will be known as a Subclass. This SavingsAccount class is a perfect candidate to use as a subclass of BankAccount since it needs all the methods and state variable of the superclass, BankAccount. To make the SavingsAccount class inherit those methods and the state variable, use the key word extends as follows: public class SavingsAccount extends BankAccount public SavingsAccount(double amount, double rate) //Constructor super(amount); //Calls the constructor in interestrate = rate; //BankAccount and sets balance public void addinterest( ) double interest = getbalance( ) * interestrate / 100; deposit(interest); private double interestrate; There are some significant features of the constructor in SavingsAccount. In the absence of super(amount), it would have tried to automatically call the BankAccount constructor and would have failed, since that constructor requires a parameter and we would not have supplied one. By making super(amount) the first line of code, we are able to supply the needed parameter. When used, it must be the first line of code in the constructor.

2 There is also something interesting in the addinterest method above. Notice that we are calling the getbalance and deposit methods. This is completely legal even though they are not static methods and we are not accessing them with a BankAccount object. Why is it legal? It is because we have inherited these methods from BankAccount by virtue of the extends BankAccount portion of our class signature. Testing the subclass and superclass: And finally, we will create a class called Tester that we will use to test the interaction of our superclass and subclass: public class Tester public static void main(string[] args) //This begins a new account in which the initial balance is 200 // and the interest rate is 5%. SavingsAccount myaccount = new SavingsAccount(200, 5); //Make a deposit notice we use an inherited method, deposit myaccount.deposit(132.14); myaccount.addinterest( ); 35-2 //Here, we use another inherited method, getbalance System.out.println( Final balance is: + myaccount.getbalance( ) ); Important terms and ideas: Superclass the original class (sometimes called the base class) Subclass the one that says extends (sometimes called the derived class) abstract a. As applied to a class Example, public abstract class MyClass prevents objects from being instantiated from the class. Why would we want to do this? Perhaps the only way we would want our class used is for it to be inherited. b. As applied to a method Example, public abstract void chamfer( ); means that no code is being implemented for this method in this class. This forces the subclass that inherits this class to implement the code there. Note that the signature of an abstract method is immediately followed by a semicolon and that there can be no body (curly braces) for the method. If any method in a class is abstract, then that forces its class to be abstract too. final a. As applied to a class public final class MyClass means no other class can inherit this one.

3 35-3 b. As applied to a method public final void bisect( ) means it can t be overridden in a subclass. See the discussion below for the meaning of overriding. Overriding if a method is defined in a superclass and is also defined in a subclass then when objects are made from the subclass, the redundant method in the subclass will take precedence over the one in the superclass. This is overriding. There is a way to access a method in a superclass that has been overridden in the subclass. Let s suppose the method s signature in both classes is: public void trans(double x) From within some method of the subclass you can access the method trans in the superclass via a command like this: super.trans(15.07); private methods not inherited: Methods and state variables in the superclass that are designated as private are not inherited by the subclass. Shadowing is when a state variable in a subclass has a name identical to that of a state variable in the superclass. We do not say that the subclass variable overrides the other, rather that it shadows it. In such cases, uses within the subclass of the redundant variable give precedence to the subclass variable. It is, however, possible to access the shadowed variable in the superclass by creating a method in the superclass to access it. Suppose that the shadowed public variable in question is double y. Then, in the superclass create this method. public double gety( ) return y; Since this method is inherited by your subclass, use it to obtain the y value in the superclass. Assuming that an object created with your subclass is called myobj, consider the following code within the subclass: double d = myobj.gety( ); // returns y from the superclass double p = myobj.y; // returns y from the subclass There is also another type of shadowing. Let s look at a method that brings in the variable z as a parameter. Complicating things is a state variable also named z. public class MyClass... public void amethod(int z) z++; //This increments the local z which has precedence here within //this method. this.z = 19; //only way to access the state variable z from within //this method.... public int z;

4 35-4 Cosmic Superclass Every class that does not extend another class automatically extends the class Object (the cosmic superclass). Following are the signatures and descriptions of four of the most important methods of the Object class. Signature String tostring( ) boolean equals(object obj) Object clone( ) int hashcode( ) Description Returns a string representation of the object. For example, for a BankAccount object we get something like BankAccount@1a28362 Tests for the equality of objects. This tests to see if two variables are references to the same object. It does not test the contents of the two objects. Produces a copy of an object. This method is not simple to use and there are several pitfalls and is therefore, rarely used. Returns an integer from the entire integer range. In many classes it is commonplace to override the inherited methods above with corresponding methods that better suit the particular class. For example, the String class overrides equals so as to actually test the contents. Table 35-1 Creation of objects: Suppose we have a superclass called SprC and a subclass called SbC. Let s look at various ways to create objects: a. SbC theobj = new SbC( ); SprC anotherobj = theobj; Since anotherobj is of type SprC it can only access methods and state variables that belong to SprC; however, overridden methods will be accessed in SbC. b. SprC hallmark = new SbC( ); Since hallmark is of type SprC it can only access methods and state variables that belong to SprC; however, overridden methods will be accessed in SbC. c. SbC obj = new SprC( ); //illegal Expecting a particular object type: Any time when a parameter is expecting to receive an object of a particular type, it is acceptable to send it an object of a subclass, but never of a superclass. This is because the passed subclass object inherits all the methods of the object. Otherwise, the expected object may have methods not in a superclass object. Consider the following hierarchy of classes where each class is a subclass of the class immediately above it. Person Male Boy

5 35-5 Suppose there is a method with the following signature: public void themethod(male ml) The method themethod is clearly expecting a Male object; therefore, the following calls to this method would be legal since we are either sending a Male object or an object of a subclass: Male m = new Male( ); themethod(m); //ok to send m since it s expecting a Male object Boy b = new Boy( ); themethod(b); //ok to send b since b is created from a subclass of Male Since themethod is expecting a Male object, we can t send an object of a superclass. Person p = new Person( ); themethod(p); //Illegal themethod( (Male)p ); //Legal if we cast p as a Male object Using the same classes from above, the following examples illustrate legal and illegal object creation. Notice when we use a class on the left, the class on the right must be either the same class or a subclass. Person p = new Male( ); //legal Person p = new Boy( ); //legal Male m = new Boy( ); //legal Boy b = new Male( ); //illegal Boy b = new Person( ); //illegal Male m = new Person( ); //illegal instanceof This method tells us if an object was created from a particular class. Suppose Parent is a superclass, Child is one of its subclasses, objp is a Parent object, and objc is a Child object. Also, assume that Circle is some unrelated class. d. (objc instanceof Child) returns a true e. (objc instanceof Parent) returns a true f. (objc instanceof Circle) returns a false g. (objp instanceof Child) returns false h. (objp instanceof Parent) returns true i. (objp instanceof Circle) returns false Notice the syntax of instanceof is that an object precedes instanceof and a class, subclass or interface follows. The big picture: The following shows the function of each part in the declaration and creation of an object in which a superclass, subclass, or interface may be involved.

6 <class, superclass, or interface name> objectname = new <class or subclass name( )>; 35-6 This specifies the object type and what methods the object can use. This tells us where the methods are implemented that we are to use ( including the constructor(s) ). Fig Determining object type, legal methods, and where the methods are implemented. If a method in the subclass overrides that of the superclass, then code in the subclass runs. Inheritance is considered one of the most important, but, unfortunately, one of the most difficult aspects of Java. See Appendix U for an enrichment activity in which you would be able to participate in electronic communities in the form of message boards (forums). Investigate the questions and answers that other programmers post concerning this topic. Exercise (A) on Lesson 35 public class Red extends Green public int blue(double x)... public String s; private int i; public class Green public double peabody(double y) return mm; private boolean crunch( )... private double mm; public long xx; 1. Which of the above two classes is the base class? 2. Which of the above two classes is the subclass? 3. Which of the above two classes is the superclass?

7 Which of the above two classes is the derived class? 5. Is this legal? If not, why not? (Assume this code is in some class other than the two above) Red myobj = new Red( ); boolean bb = myobj.crunch( ); 6. Is this legal? If not, why not? (Assume this code is in some class other than the two above) Red myobj = new Red( ); int bb = myobj.blue(105.2); 7. Write code for the blue method that will printout the mm state variable. 8. Write code for the blue method that will printout the xx state variable. Use the following two classes for problems 9-12: public class Red extends Green public int blue(double x)... public double peabody(double vv) public String s; private int i; public class Green public Green(long j) xx = j; public double peabody(double y) return mm; private Boolean crunch( )... private double mm; public long xx;

8 Consider the following constructor in the Red class: public Red( ) //What code would you put here to invoke the constructor in the //superclass and send it a parameter value of 32000? 10. Is there any method in Red that is overriding a method in Green? If so, what is it? 11. Look at the peabody method inside Red. Write the code inside that method that will allow you to access the same method inside its superclass, Green. Let the parameter have a value of Consider the following constructor in the Red class: public Red( ) String s = Hello ; super(49); Is this code legal? If not, why not? 13. Assume that the following fragments of code are all in a subclass. Match each to an item from the sentence bank to the right. this(x,y) this.z super(j) super.calc( ) a. refers to a constructor in the superclass b. refers to a constructor in the subclass c. refers to an overridden method in the super class d. refers to a data member in the subclass

9 35-9 Exercise (B) on Lesson 35 The following code applies to problems 1-3: public abstract class Hammer public abstract void duty( ); public abstract int rule(int d); public class Lurch extends Hammer public void duty( ) int x = Y; public int rule( int d) Y = d + 1; return Y; private int Y = 30; private int x; 1. What is the purpose of making the two methods above abstract? 2. Write out the full signature of the rule method. 3. Which class actually implements the duty method? 4. A class for which you cannot create objects is called a (an) class. 5. public abstract class Felix... Is the following attempt at instantiating an object from the Felix class legal? If not, why? Felix myfelix = new Felix( );

10 Is the following legal? If not, why? public abstract class Lupe public abstract void fierce( )... public final double PI = 3.14; 7. What is the main reason for using abstract classes? 8. Modify the following class so it is impossible to make subclasses from it. public class MyClass Why would the following code be pointless? public final abstract class MyClass... //there are no static methods 10. public class ChevyChase public void Chicago(int x)... Modify the above code so as to make it impossible for a subclass that extends ChevyChase to override the Chicago method. 11. Is it possible to override instance fields (also called state variables)? 12. What is shadowing (as the term applies to superclasses and subclasses)?

11 35-11 The following code applies to problems 13 14, 18-20: public class Parent public void rubydoo( ) public int x = 0; public class Child extends Parent public void busterstein( ) public int x = 39; 13. Consider the following code in a Tester class: Child mychild = new Child( ); System.out.println(myChild.x); //What gets printed? 14. Consider the following code in a Tester class: Child mychild = new Child( ); Is there any way using the mychild object to retrieve the x state field within the Parent class? Write the code that will do this. You may write a new method for either class if you need to. 15. What is the name of the Cosmic Superclass? 16. What is the name of the class that every class (that does not extend another class) automatically extends? 17. What are the four main methods of the Object class?

12 Is the following legal? If not, why not? Child theobj = new Child( ); Parent newobj = theobj; newobj.busterstein( ); 19. Is the following legal? If not, why not? Child theobj = new Child( ); Parent newobj = theobj; newobj.rubydoo( ); 20. Is the following legal? If not, why not? Parent meatloaf = new Child( ); For problems 21-25, consider the following. In each problem either state what is printed or indicate that it won t compile: public class A public A (int x) this.x = x; public int f( ) return x; public int g( ) return x; public int x;

13 35-13 public class B extends A public B (int x, int y) super(x); this.x = y; public int f( ) return x + g( ); public int zorro( ) return x + g( ); public int x; 21. A a = new B(5, 10); System.out.println(a.g( )); 22. A a = new B(5, 10); System.out.println( a.f( ) ); 23. A a = new B(5, 10); System.out.println( a.x ); 24. B a = new B(5, 10); System.out.println( a.x ); 25. A a = new B(5, 10); System.out.println( a.zorro( ) ); *********************************************************** 26. Consider the classes Food, Cheese, and Velveeta where Cheese is a subclass of Food and Velveeta is a subclass of Cheese. State which of the following lines of code are legal. Cheese c = new Food( ); Velveeta v = new Food( ); Cheese c = new Velveeta( ); Food f = new Velveeta( ); Food f = new Cheese( );

14 Inheritance Contest Type Problems 1. What replaces <*1> and <*2> in the code to the right to indicate that objects cannot be instantiated and that the methods are not being defined? A. <*1>: abstract <*2>: abstract B. <*1>: abstract <*2>: final C. <*1>: final <*2>: abstract D. <*1>: final <*2>: final 2. The interest earned on a loan is the product of 1/12, the principle, the rate, and the months. What replaces <*3> in the code to the right to correctly compute the interestearned( ) method? A. months / 12 * rate * ad.getprinciple( ) B. months * rate * ad.getprinciple( ) / 12 C. Loan.months /12 * Loan.rate * ad.getprinciple D. months * rate * ad.getprinciple( ) * (1/12) E. More than one of these 3. Assume that the class Info is a subclass of AccountDetails and has a constructor which receives a double and a String. Which of the following builds a Loan p object with rate.07, months 4, and principle $450? A. Loan p (.07, 4, new Info(450, Bob )); B. Loan p = Loan(.07, 4, new Info(450, Bob )); C. Loan p = new Loan(.07, 4, Info(450, Bob )); D. Loan p = new Loan(.07, 4, new Info(450, Bob )); 4. What is output by the code below? Parent pr = new Parent(7); System.out.print(pr.work( )); A. 1 B. 0 C. 3 D What is output by the code below? Parent pr = new Child(4, 11); System.out.print(pr.work( )); A. 11 B. 4 C. 1 D public <*1> AccountDetails public <*2> double getprinciple( ); public <*2> String getname( ); public <*1> class Financial public <*2> double interestearned( ); public <*2> double paymentdue( ); public class Loan extends Financial public Loan(double rate, int months, AccountDetails ad) this.rate = rate; this.months = months; this.ad = ad; public double interestearned( ) return <*3>; public double paymentdue( ) //code not shown private double rate; private int months; AccountDetails ad; public class Parent public Parent(int q) this.q = q; public int work( ) return q; private int q; public class Child extends Parent public Child(int q, int y) super(q); this.y = y; public int work( ) return y + super.work( ); private int y;

15 6. What replaces <*1> in the code to the right that causes Z to inherit class A? A. implements A B. subclass of A C. subclass of class A D. extends A E. inherits A 7. Which of the following replaces <*1> in the code to the right so that the default constructor builds a Triangle object with base 2 and altitude 5? A. this(2, 5); B. Triangle (2, 5); C. super(2, 5); D. this(base) = 2; this(altitude) = 5; E. More than one of these 8. Assume that <*1> has been filled in correctly. Which of the following returns the area of EquilateralTri et? A. (EquilateralTri)et.area( ) B. et.super.area( ) C. et.(equilateraltri)area( ) D. et.area( ) 9. Given a Triangle tri that is initialized to hold a Triangle and an EquilateralTri et that is initialized to hold a Triangle, which of the following expressions evaluates to true? A. Triangle instanceof EquilateralTri B. tri instanceof et C. tri instanceof EquilateralTri D. Triangle instanceof Object 10. Suppose st is a Street object. Which of these is a valid call to method House.getInfo( ) using st as an argument? A. st.getinfo(town t) B. House.getInfo( (Town)st ) C. House.getInfo( Town(st) ) D. House.getInfo(Town.st) 11. Suppose st is a Street object. What is the value of this expression? st instanceof Town A. 0 B. true C. 1 D. false public class Z <*1> //methods and data not shown public class Triangle public Triangle( ) <*1> public Triangle(int bs, int alt) base = bs; altitude = alt; public double area( ) return.5 * base * altitude; private int base; private int altitude; public class EquilateralTri extends Triangle public EquilateralTri (int s) super(s, s * Math.sqrt(3)/2); this.s = s; private int s; public class Town //code not shown public class Street extends Town //code not shown public class House public static void getinfo(town t) //code not shown 35-15

16 12. Given the declarations below, which of the following expressions is true? Car cr = new Car( ); Chevy chv = new Chevy( ); Lumina lm = new Lumina( ); A. cr instanceof Chevy B. chv instanceof Lumina C. cr instanceof Lumina D. lm instanceof Car E. More than one of these 13. Suppose that the static method dostuff( ) of class Engine takes a parameter of type Lumina. Given the declarations below, which of these is a valid call to dostuff( )? Car cr = new Lumina( ); Chevy chv = new Lumina( ); Lumina lm = new Lumina( ); A. Engine.doStuff(chv) B. Engine.doStuff(cr) C. Engine.doStuff(lm) D. dostuff((car)lm) public class Car //methods and data not shown public class Chevy extends Car //methods and data not shown public class Lumina extends Chevy //methods and data not shown Suppose that Insect is an abstract class, that Bee is a class that extends Insect, and that Drone is a class that extends Bee. Given the following declaration, which of these is true? Drone d = new Drone( ); A. d instanceof Object B. d instanceof Insect C. d instanceof Bee D. d instanceof Drone E. All of these 15. If class Man is a subclass of class Person, what is the syntax for calling a private method of Person named meth( ) from within a private method of Man? A. this.meth( ) B. meth( ) C. super.meth( ) D. super( meth( ) ) 16. Which of the following replaces <*1> in the code to the right to call the constructor for the Pasta class with the parameter g? A. this(g); B. super(g); C. x.super( ); D. Pasta(g); public class Spaghetti extends Pasta public Spaghetti(int g, int h) <*1> remaining code not shown

Inheritance (P1 2006/2007)

Inheritance (P1 2006/2007) Inheritance (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To learn about

More information

Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13

Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about inheritance To understand how

More information

Inheritance & Abstract Classes Fall 2018 Margaret Reid-Miller

Inheritance & Abstract Classes Fall 2018 Margaret Reid-Miller Inheritance & Abstract Classes 15-121 Margaret Reid-Miller Today Today: Finish circular queues Exercise: Reverse queue values Inheritance Abstract Classes Clone 15-121 (Reid-Miller) 2 Object Oriented Programming

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

Chapter Goals. Chapter 9 Inheritance. Inheritance Hierarchies. Inheritance Hierarchies. Set of classes can form an inheritance hierarchy

Chapter Goals. Chapter 9 Inheritance. Inheritance Hierarchies. Inheritance Hierarchies. Set of classes can form an inheritance hierarchy Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package access control To

More information

Handout 9 OO Inheritance.

Handout 9 OO Inheritance. Handout 9 CS603 Object-Oriented Programming Fall 2016 Page 1 of 11 Handout 9 OO Inheritance. All classes in Java form a hierarchy. The top of the hierarchy is class Object Example: classicalarchives.com

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

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

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

CHAPTER 10 INHERITANCE

CHAPTER 10 INHERITANCE CHAPTER 10 INHERITANCE Inheritance Inheritance: extend classes by adding or redefining methods, and adding instance fields Example: Savings account = bank account with interest class SavingsAccount extends

More information

INHERITANCE. Spring 2019

INHERITANCE. Spring 2019 INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose

More information

Chapter 10 Inheritance. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Chapter 10 Inheritance. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 10 Inheritance Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

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

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017 Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

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

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

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

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

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

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

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8 Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 1 Problem Ralph owns the Trinidad Fruit Stand that sells its fruit on the street, and he wants to use a computer

More information

Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal

Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Define and discuss abstract classes Define and discuss abstract methods Introduce polymorphism Much of the information

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

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

Check out Polymorphism from SVN. Object & Polymorphism

Check out Polymorphism from SVN. Object & Polymorphism Check out Polymorphism from SVN Object & Polymorphism Inheritance, Associations, and Dependencies Generalization (superclass) Specialization (subclass) Dependency lines are dashed Field association lines

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

CLASS DESIGN. Objectives MODULE 4

CLASS DESIGN. Objectives MODULE 4 MODULE 4 CLASS DESIGN Objectives > After completing this lesson, you should be able to do the following: Use access levels: private, protected, default, and public. Override methods Overload constructors

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 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 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

Basics of Java Programming. Hendrik Speleers

Basics of Java Programming. Hendrik Speleers Hendrik Speleers Overview Building blocks of a Java program Classes Objects Primitives Methods Memory management Making a (simple) Java program Baby example Bank account system A Java program Consists

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

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

Final Exam CS 251, Intermediate Programming December 13, 2017

Final Exam CS 251, Intermediate Programming December 13, 2017 Final Exam CS 251, Intermediate Programming December 13, 2017 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible

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

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

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 CS-140 Fall 2017 Test 2 Version A Nov. 29, 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 : An interface defines the list of fields

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

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

COSC This week. Will Learn

COSC This week. Will Learn This week COSC1030.03 Read chapters 9, 11 S tart thinking about assignment 2 Week 4. J anuary 26, 2004 Will Learn how to inherit and override superclass methods how to invoke superclass constructors about

More information

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1 Inheritance & Polymorphism Recap Inheritance & Polymorphism 1 Introduction! Besides composition, another form of reuse is inheritance.! With inheritance, an object can inherit behavior from another object,

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Abstract Classes and Interfaces

Abstract Classes and Interfaces Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass

More information

More about inheritance

More about inheritance Main concepts to be covered More about inheritance Exploring polymorphism method polymorphism static and dynamic type overriding dynamic method lookup protected access 4.1 The inheritance hierarchy Conflicting

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

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Islamic University of Gaza Faculty of Engineering Computer Engineering Department Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B

More information

Polymorphism. return a.doublevalue() + b.doublevalue();

Polymorphism. return a.doublevalue() + b.doublevalue(); Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces

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

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information

Inheritance (Part 2) Notes Chapter 6

Inheritance (Part 2) Notes Chapter 6 Inheritance (Part 2) Notes Chapter 6 1 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 2 Implementing Inheritance suppose you want to

More information

Computer Science II (20082) Week 1: Review and Inheritance

Computer Science II (20082) Week 1: Review and Inheritance Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax

More information

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018 Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside

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

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008 Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object

More information

Software and Programming I. Classes and Arrays. Roman Kontchakov / Carsten Fuhs. Birkbeck, University of London

Software and Programming I. Classes and Arrays. Roman Kontchakov / Carsten Fuhs. Birkbeck, University of London Software and Programming I Classes and Arrays Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Class Object Interfaces Arrays Sections 9.5 9.6 Common Array Algorithms Sections 6.1

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

Lesson 43.. ArrayList

Lesson 43.. ArrayList Lesson 43.. ArrayList 43-1 You will recall from Lesson 42 the ArrayList is one of several classes that implement the List interface. As its name suggests, ArrayList also involves arrays. Basically, everything

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

Programming in the Large II: Objects and Classes (Part 2)

Programming in the Large II: Objects and Classes (Part 2) Programming in the Large II: Objects and Classes (Part 2) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen

More information

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

STUDENT LESSON A5 Designing and Using Classes

STUDENT LESSON A5 Designing and Using Classes STUDENT LESSON A5 Designing and Using Classes 1 STUDENT LESSON A5 Designing and Using Classes INTRODUCTION: This lesson discusses how to design your own classes. This can be the most challenging part of

More information

Inheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism. superclass. is-a. subclass

Inheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism. superclass. is-a. subclass Inheritance and Polymorphism Inheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism Inheritance (semantics) We now have two classes that do essentially the same thing The fields are exactly

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

AP CS Unit 6: Inheritance Notes

AP CS Unit 6: Inheritance Notes AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

COMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation

COMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation COMP-202 Unit 8: Defining Your Own Classes CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation Defining Our Own Classes (1) So far, we have been creating

More information

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW Prepared by: Dr. Abdallah Mohamed, AOU-KW 1 1. Introduction 2. Objects and classes 3. Information hiding 4. Constructors 5. Some examples of Java classes 6. Inheritance revisited 7. The class hierarchy

More information

Programming overview

Programming overview Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in

More information

Instance Members and Static Members

Instance Members and Static Members Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

PROGRAMMING III OOP. JAVA LANGUAGE COURSE

PROGRAMMING III OOP. JAVA LANGUAGE COURSE COURSE 3 PROGRAMMING III OOP. JAVA LANGUAGE PREVIOUS COURSE CONTENT Classes Objects Object class Acess control specifier fields methods classes COUSE CONTENT Inheritance Abstract classes Interfaces instanceof

More information

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Final Exam CS 251, Intermediate Programming December 10, 2014

Final Exam CS 251, Intermediate Programming December 10, 2014 Final Exam CS 251, Intermediate Programming December 10, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible

More information

CS1150 Principles of Computer Science Objects and Classes

CS1150 Principles of Computer Science Objects and Classes CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8

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

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

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

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

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

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Midterm Exam CS 251, Intermediate Programming March 6, 2015 Midterm Exam CS 251, Intermediate Programming March 6, 2015 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible

More information

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism Ibrahim Albluwi Composition A GuitarString has a RingBuffer. A MarkovModel has a Symbol Table. A Symbol Table has a Binary

More information

Principles of Software Construction: Objects, Design and Concurrency. Inheritance, type-checking, and method dispatch. toad

Principles of Software Construction: Objects, Design and Concurrency. Inheritance, type-checking, and method dispatch. toad Principles of Software Construction: Objects, Design and Concurrency 15-214 toad Inheritance, type-checking, and method dispatch Fall 2013 Jonathan Aldrich Charlie Garrod School of Computer Science 2012-13

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

COMP 110/L Lecture 19. Kyle Dewey

COMP 110/L Lecture 19. Kyle Dewey COMP 110/L Lecture 19 Kyle Dewey Outline Inheritance extends super Method overriding Automatically-generated constructors Inheritance Recap -We talked about object-oriented programming being about objects

More information

Chapter 5. Inheritance

Chapter 5. Inheritance Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super

More information