Class vs Abstract vs Interface

Slides:



Advertisements
Similar presentations
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.
Advertisements

CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
ITEC200 – Week03 Inheritance and Class Hierarchies.
More about classes and objects Classes in Visual Basic.NET.
TA: Nouf Al-Harbi NoufNaief.net :::
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
1 Evan Korth New York University abstract classes and casting Professor Evan Korth New York University.
Inheritance COMP53 Sept Inheritance Inheritance allows us to define new classes by extending existing classes. A child class inherits all members.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
Abstract Classes b b An abstract class is a placeholder in a class hierarchy that represents a generic concept b b An abstract class cannot be instantiated.
Inheritance using Java
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
CS305j Introduction to Computing Inheritance and Polymorphism 1 Topic 26 Introduction to Inheritance and Polymorphism "One purpose of CRC cards [a design.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Inheritance in the Java programming language J. W. Rider.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Coming up: Inheritance
Inheritance 2 Mehdi Einali Advanced Programming in Java 1.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Object-Oriented Programming: Polymorphism Chapter 10.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Polymorphism in Methods
Modern Programming Tools And Techniques-I
Web Design & Development Lecture 9
Chapter 15 Abstract Classes and Interfaces
Advanced Programming in Java
Advanced Programming in Java
Advanced Programming in Java
Lecture 10 Review of classes
Final and Abstract Classes
Inheritance and Polymorphism
abstract classes and casting objects
Chapter 13 Abstract Classes and Interfaces
Object Oriented Programming
Inheritance, Polymorphism, and Interfaces. Oh My
Object Oriented Programming (OOP) LAB # 8
Inheritance Chapter 7 Chapter 7.
Inheritance, Polymorphism, and Interfaces. Oh My
Chapter 9: Polymorphism and Inheritance
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Advanced Java Programming
Java Inheritance.
Advanced Programming in Java
Chapter 14 Abstract Classes and Interfaces
Chapter 8 Class Inheritance and Interfaces
Final and Abstract Classes
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Class vs Abstract vs Interface

Class 100% concrete (full defined) data type All methods are fully implemented May be directly instantiated (created) but invoking one of its constructors

extends Parent – Child Classes A class (fully functioning) may have sub-classes. The subclass inherits functionality from the parent

Student is the parent class HighSchoolStudent is-A student HighSchoolStudent inherits from Student Notice that HighSchoolStudent does NOT have a name field or methods related to name. These things are inherited and therefore you do not repeat them in the child class. Is-A

c.getName() will work because HighSchoolStudent inherited that method from Student

b is a reference to a Student object – when you output b it looks to see what type of Student is it actually referencing and calls the toString of the HighSchoolStudent class.

Abstract Incomplete class definition (conceptual) May include fully implemented methods May include unimplemented abstract methods Cannot be directly instantiated Subclasses of an abstract class must: Implement all the abstract methods Or Be declared as abstract also

This class is abstract because there is not a default area or perimeter formula

Both Square and Circle inherit name from the Shape class. Both Square and Circle implement getArea() and getPerimeter() with the correct formula.

The output is calling the toString for each object The output is calling the toString for each object. In the toString the getArea() and getPerimeter() methods are called. Java uses dynamic binding to call the correct getArea() method – meaning if it is a Circle Java will call Circle’s getArea() and if it is a Square Java will call Square’s getArea()

You cannot instantiate a Shape because it is abstract s.getArea() would not work because getArea is abstract in the Shape class.

Interface 100% abstract (conceptual) data type Declares what operations (functionality) the type will have Doesn’t define any operations (no implemented methods) Only abstract methods Cannot be directly instantiated (NO CONSTRUCTOR)