Ch 13. Features Found Only in Java Timothy Budd Oregon State University.

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen.
Object Oriented Programming
1 Inheritance Lecture 9 from Chapter 8. 2 Review Command line arguments Basic Inheritance Member access and inheritance Using super Creating a multi-level.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Ch. 17 Case Study Combining Separate Classes Timothy Budd Oregon State University.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Advanced Object-Oriented Programming Features
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Abstract Classes and Interfaces
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
OOP Languages: Java vs C++
Inheritance using Java
Inheritance in C++ CS-1030 Dr. Mark L. Hornick.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Inheritance in the Java programming language J. W. Rider.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
Nested Classes CompSci 230 S Software Construction.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Variations on Inheritance Object-Oriented Programming Spring
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Object-Oriented Programming: Polymorphism Chapter 10.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
1 DemoBasic_v3, DemoBasic_v4 JButton JLabel. 2 Registering an ActionListener Register by invoking the following from within constructor DemoBasicFrame.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
Inheritance and Big O And your first reading assignment
Polymorphism, Abstract Classes & Interfaces
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Interface.
Java Programming Language
Abstract Classes AKEEL AHMED.
Interfaces.
Polymorphism, Abstract Classes & Interfaces
Polymorphism Polymorphism
Lecture 10 Concepts of Programming Languages
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Presentation transcript:

Ch 13. Features Found Only in Java Timothy Budd Oregon State University

Ch 13. Features Found Only in Java2 Introduction The number of features found in Java that have no C++ counterpart is relatively small. We mention only the most notable items that have not discussed elsewhere.

Ch 13. Features Found Only in Java3 Wrapper Classes Java defines a “wrapper” class for each of the primitive data types. Primary reason is that primitive data types are not objects, thus cannot be assigned to a value of type Object, and hence cannot be stored in any of the standard data structures. In C++, template classes and functions eliminate most of the need for wrapper classes.

Ch 13. Features Found Only in Java4 Interfaces Interfaces describes the behavior associated with a class but does not provide an implementation. C++ does not have any exact equivalent; the closest is a method that does not have a body. class GraphicalObject { public: virtual draw() = 0; // every subclass must override };

Ch 13. Features Found Only in Java5 Interfaces Any class that inherits from a class the includes a pure virtual function must override these functions. An interface can be thought of as a class description in which every method has been declared as pure virtual.

Ch 13. Features Found Only in Java6 Inline Classes When need to create a class that will have only a single instance. Because the class name is not needed, Java provides a way for creating instatances of a class without naming the class: inline class. Inline classes are formed by naming the parent class and specifying whatever new or overridden methods the class requires. Cannot have constructors and cannot have more than one instance.

Ch 13. Features Found Only in Java7 Example of Inline Class class Example extends Frame { public Example () { Button a = new Button("quit");... a.addActionListener( new ActionListener() { // create in-line class public void actionPerformed(ActionEvent & e) { System.exit(1); // quit program } } ); } }

Ch 13. Features Found Only in Java8 Inline Classes While C++ does not have correspondence to the inline class feature, it is possible to create nested classes that do not have names. Such classes cannot have either constructors nor destructors.

Ch 13. Features Found Only in Java9 C++ Example of anonymous Class The example class contains an unnamed nested class that defines two data fields. An instance of this class is held by the field named data in the outer class: class Example { // C++ example of anonymous class public: private: class { public: int x; int y; } data; };

Ch 13. Features Found Only in Java10 Threads Java includes extensive facilities for multiprocessing as part of the basic language. In C++, not part of the language but instead are provided as external libraries. Thread programming is both more difficult and less portable than in Java.

Ch 13. Features Found Only in Java11 Reflection Java permits the program to discover information about the currently running program, this is called Reflection. Reflection begins with the class Class. Every object can be asked its class and will respond with an instance of this class. Using the class object, we can discover the methods that an object implements, and use the class object to create new instances of a class. A class object can return the class object that represents its parent class.

Ch 13. Features Found Only in Java12 Reflection The classes Field and Method provide similar information about data fields and members. Can even dynamically create, initialize, and load new classes into a running program. Not part of the standard language C++, although it is possible for objects to access their type as a string value. To a limited extent, reflection facilities can be implemented in a platform-specific manner by external libraries.