More Inheritance and More Java Stuff 9-12-2002. Opening Discussion zWhat did we talk about last class? zHave you read the description of assignment #2?

Slides:



Advertisements
Similar presentations
Inner Classes. Nested Classes  An nested class is a class that is defined inside another class.  To this point we have only studied top-level classes.
Advertisements

Programming With Java ICS201 University Of Hail1 Chapter 13 Inner Classes.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Unit 08 & 091 Nested Classes Introduction Inner Classes Local Classes Anonymous Classes Exercises.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 27 - Java Object-Oriented Programming Outline.
Unit 081 Introduction to Nested Classes Nested classes are classes defined within other classes The class that includes the nested class is called the.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Abstract Superclasses and Abstract Methods When.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Intro to C++ And Some Tools Opening Discussion zHave any questions come up since last class? Have you had a chance to look over the project.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Object Oriented Programming: Java Edition By: Samuel Robinson.
String Processing Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have questions.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
MIPS Machine Assembly Language Opening Discussion zWhat did we talk about last class? zHave you seen anything interesting in the news? zDo you.
2-Dec-15 Inner Classes. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Threads Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment?
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Constructors & Garbage Collection Ch. 9 – Head First Java.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Arrays: Part Opening Discussion zWhat did we talk about last class? zWhat do you think the picture of memory looks like when we declare.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Conditionals Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zPass by value limitations.
Nested Classes CompSci 230 S Software Construction.
Written by: Dr. JJ Shepherd
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Advanced Java class Nested Classes & Interfaces. Types of Nested Classes & Interfaces top-level nested –classes –interfaces inner classes –member –local.
Inheritance and Virtual Functions Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class?
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
BY:- TOPS Technologies
Inner Classes.
Topic: Inner Classes Course : JAVA PROGRAMMING Paper Code: ETCS-307 Faculty : Dr. Prabhjot Kaur Reader, Dept. of IT 1.
Inner Classes 27-Dec-17.
Programming in Java: lecture 7
Objects as a programming concept
CompSci 230 S Programming Techniques
CS230 Tutorial Week 3.
Nested class.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
Overloading and Overriding
Inner Classes 29-Nov-18.
Java – Inheritance.
Java Inheritance.
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 1-May-19.
Inner Classes 11-May-19.
Inner Classes 18-May-19.
Topics OOP Review Inheritance Review Abstract Classes
Inner Classes.
Inner Classes 25-Oct-19.
Presentation transcript:

More Inheritance and More Java Stuff

Opening Discussion zWhat did we talk about last class? zHave you read the description of assignment #2? Do you have any questions about it?

Difficulties with Inheritance zFor the minute essay last time I asked you about problems with inheritance. zOne significant problem can be frailty. You have to think about the public interfaces of base classes very carefully because when you have many subclasses it is almost impossible to change them. Also worry about public methods that call other public methods.

Ref Types and Arg Passing zIn C/C++ you had the choice of passing by value or passing by reference. I C, passing by reference was done by passing a pointer. In C++ you could pass a pointer or a “reference”. zJava has only passing by value, but with the condition that all object variables are reference variables. zIf you want to return two things you return and object with them in it.

The super Keyword zSometimes you want to be able to access methods or constructors from the superclass of a given class. In Java this is done with the super keyword. yFor constructors the first line of a constructor can be super(arg1,arg2,...); to call the constructor of the superclass that takes the given argument list. yFor other methods, using super.method(…) will call that method of the superclass.

Inner Classes zStarting with version 1.1, Java introduced inner classes. The simplistic view of inner classes is that they are classes inside of other classes. You can do this in C++. zThe full reality is that inner classes in Java have more complexity than an embedded class in C++. For one thing, unless you state otherwise, inner classes keep track of the instance of the “outer class” that creates them.

Static Inner Classes zThe construct in Java that is most like an embedded class in C++ is a static inner class. zThe instances of this inner class are associated with the class as a whole. zUnlike in C++, they have access to all static methods and members of the outer class. zMake inner classes static unless they need to be otherwise.

Non-static Inner Classes zIf an inner class is not declared static, it will get a reference to the instance of the outer class in which it is created. zThis gives it access to all methods and members of that instance. The methods of the inner class can access the private data of the outer class. zThis adds some overhead, but can be very handy at times.

Anonymous Inner Classes zJava has another construct that has no parallel in C++, the anonymous inner class. zAs the name implies, these classes have no names. Instead, they have to be a subtype of some class or interface. They can then be used as an instance of the supertype. zThey allow you to create a class “inline”, in the code for a method.

More on Anonymous ICs zThey are static or not depending on the type of method they are created in. zThey have access to all the things the named inner classes of their type would have, plus the final variables in the method in which they are declared. zThese are used extensively for event handling in Java GUIs.

Let’s write some code zNow let’s write some code that demonstrates all the majors syntactic points of Java that we have talked about and displays inheritance.

Minute Essay zNext class is on string processing. This means that we are going to move away from talking about the nature of the language itself. What questions do you still have about the Java language? Do you feel comfortable trying to code assignment #2 and if not what would help? zQuiz #1 is on Tuesday.