Modern Fortran OO Features
|
|
- Rudolph Ray
- 6 years ago
- Views:
Transcription
1 Modern Fortran OO Features Salvatore Filippone School of Aerospace, Transport and Manufacturing, IT4I, Ostrava, April 2016 S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
2 Preface Premature optimization is the root of all evil Knuth Donald Write 80% of your source code with yourself and your fellow programmers in mind, i.e. to make your life easier, not your computers life easier. The CPU will never read your source code without an interpreter or compiler anyway. Arcane or quirky constructs and names to impress upon the CPU the urgency or seriousness of your task might well get lost in the translation. S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
3 Preface Procedural programming is like an N-body problem Lester Dye The overwhelming amount of time spent in maintenance and debugging is on finding bugs and taking the time to avoid unwanted side effects. The actual fix is relatively short! Shalloway & Trott, Design Patterns Explained, S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
4 OOP Recap By widely held received wisdom, Object-Oriented Programming emphasizes the following features: 1 Encapsulation 2 Inheritance 3 Polymorphism All three are supported by Fortran. S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
5 OOP nomenclature Fortran C++ General Extensible derived type Class Abstract data type Component Data member Attribute class Base class pointer Dynamic Polymorphism Type guarding (select type) RTTI (dynamic cast) Type-bound procedure Virtual Member functions Method, operation* Parent type Base class Parent class Extended type Subclass Child class Module Namespace Package Generic interface Function overloading Static polymorphism Final Procedure Destructor Defined operator Overloaded operator Defined assignment Overloaded assignment Deferred procedure binding Pure virtual member function Abstract method Procedure interface Function prototype Procedure signature Intrinsic type/procedure Primitive type/procedure Built-in type procedure S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
6 Encapsulation: Type-bound procedures The first tenet of OOP is encapsulation: Package data, and bring the code (method) close to the data (object) The Fortran concepts for this are derived types (which we have already seen) and type-bound procedures. module astronaut_class implicit none private! Hide everything by default public :: astronaut! Expose type & constructor integer,parameter :: max_string_length=100 type astronaut private character(len=max_string_length) :: greeting procedure :: greet! Public by default end type function greet(this) result(message) class(astronaut), intent(in) :: this character(len=max_string_length) :: message message = this%greeting end function end module program oo_hello_world use astronaut_class,only : astronaut type(astronaut) :: pilot pilot = astronaut( Hello, world! ) print *, pilot%greet() end program S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
7 Encapsulation: Type-bound procedures Features of type-bound procedures: The name by which the procedure is invoked; The object on which it is invoked; The visibility; The extensibility (to be further explored later); Generic type-bound procedures S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
8 Encapsulation: Type-bound procedures module psb_base_mat_mod type :: psb_base_sparse_mat!> Row size integer(psb_ipk_), private :: m!> Col size integer(psb_ipk_), private :: n!> Matrix state: integer(psb_ipk_), private :: state integer(psb_ipk_), private :: duplicate logical, private :: triangle logical, private :: upper logical, private :: unitd logical, private :: sorted logical, private :: repeatable_updates=.false. function psb_base_get_fmt() result(res) implicit none character(len=5) :: res res = NULL end function psb_base_get_fmt! function psb_base_get_nrows(a) result(res) implicit none class(psb_base_sparse_mat), intent(in) :: a integer(psb_ipk_) :: res res = a%m end function psb_base_get_nrows procedure, pass(a) :: get_nrows => psb_base_get_nrows procedure, pass(a) :: get_ncols => psb_base_get_ncols procedure, nopass :: get_fmt => psb_base_get_fmt end type psb_base_sparse_mat function psb_base_get_ncols(a) result(res) implicit none class(psb_base_sparse_mat), intent(in) :: a integer(psb_ipk_) :: res res = a%n end function psb_base_get_ncols end module psb_base_mat_mod S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
9 Encapsulation: Type-bound procedures Type-bound procedures can be generic type :: psb_base_sparse_mat... procedure, pass(a) :: transp_1mat => psb_base_transp_1mat procedure, pass(a) :: transp_2mat => psb_base_transp_2mat generic, public :: transp => transp_1mat, transp_2mat end type psb_base_sparse_mat subroutine psb_base_transp_1mat(a) class(psb_base_sparse_mat), intent(inout) :: a integer(psb_ipk_) :: itmp itmp = a%m a%m = a%n a%n = itmp a%triangle = a%triangle a%upper =.not.a%upper end subroutine psb_base_transp_1mat subroutine psb_base_transp_2mat(a,b) class(psb_base_sparse_mat), intent(in) :: a class(psb_base_sparse_mat), intent(out) :: b b%m = a%n b%n = a%m b%triangle = a%triangle b%upper =.not.a%upper end subroutine psb_base_transp_2mat S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
10 Inheritance: extending types The second tenet of OOP is inheritance: Embrace and extend existing types type :: speaker procedure(talk),deferred :: speak end type abstract interface function talk(this) result(message) import :: speaker,msg_max_length class(speaker),intent(in) :: this!character(:),allocatable :: message character(len=msg_max_length) :: message end function end interface S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
11 Inheritance: extending types type,extends(speaker) :: astronaut private character(len=msg_max_length) :: greeting procedure :: speak => greet end type function greet(this) result(message) class(astronaut),intent(in) :: this character(len=msg_max_length) :: message message = this%greeting end function S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
12 Inheritance: extending types Rules: The extended type implicitly has all the comoponents of the parent type; The extended type implicitly has the parent type as a component; The extended type implicitly gets all of the methods of the parent type; You should only ever override specific procedures, generics work automatically S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
13 Polymorphism: static and dynamic The third tenet of OOP is polymorphism: Object instances may have different types Comes in two main varieties: Static polymorphism: the actual type can be resolved at compile time; Dynamic polymorphism: the actual type can only be resolved at runtime. Static polymorphism corresponds to the resolution of generic interfaces; we have already seen this in Fortran 95. S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
14 Morpheus: Greek god of dreams S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
15 Polymorphism Dynamic polymorphism is signalled by the CLASS keyword; a polymorphic entity must be either A dummy argument; A variable with the ALLOCATABLE attribute; A variable with the POINTER attribute; Examples: type point real :: x,y end type point type(point) :: vp class(point), pointer :: pp pp => vp S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
16 Polymorphism A polymorphic variable may get its type by: The actual argument passed to a subroutine; The association between a pointer and a target; Specifying explicitly a type in an ALLOCATE statement. class(base_type), allocatable :: item... allocate(extended_type :: item) Specifying a SOURCE or MOLD in the ALLOCATE statement. type(extended_type) :: foo class(base_type), allocatable :: item... allocate(item,source=foo) S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
17 Polymorphism Fine points: The CLASS specifier must appear for the passed object in all type-bound procedures (except those marked as FINAL); The CLASS specifier may or may not appear for other variables; Through a polymorphic variable you can only invoke methods of the declared type S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
18 Polymorphism The SELECT TYPE (aka type guard) construct allows fine discrimination among related types subroutine print_particle(p) class(particle) :: p call print_vector( position,p%position()) call print_vector( momentum,p%momentum()) select type (p) type is (charged_particle) print *, Charge is:,p%charge() class is (charged_particle) print *, Charge is:,p%charge() print *, May have other features type is (particle) print *, Base particle type, nothing special class default print *, Unknown particle type end select end subroutine print_particle S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
19 Type inquiry functions extends type of(a,b) True if the type of a is an extension of the type of b same type as(a,b) True if the type of a is an extension of the type of b S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
20 The parent type component type :: psb_base_sparse_mat... procedure, pass(a) :: transp_1mat => psb_base_transp_1mat procedure, pass(a) :: transp_2mat => psb_base_transp_2mat generic, public :: transp => transp_1mat, transp_2mat end type psb_base_sparse_mat type, extends(psb_d_base_sparse_mat) :: psb_d_coo_sparse_mat procedure, pass(a) :: transp_1mat => d_coo_transp_1mat end type S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
21 The parent type component subroutine d_coo_transp_1mat(a) implicit none class(psb_d_coo_sparse_mat), intent(inout) :: a integer(psb_ipk_), allocatable :: itemp(:) integer(psb_ipk_) :: info call a%psb_d_base_sparse_mat%transp() call move_alloc(a%ia,itemp) call move_alloc(a%ja,a%ia) call move_alloc(itemp,a%ja) call a%set_sorted(.false.) call a%set_sort_status(psb_unsorted_) return end subroutine d_coo_transp_1mat S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
22 abstract and deferred A type can be defined as abstract, in which case it cannot be instantiated directly type, abstract :: file_handle procedure(open_file), deferred, pass(handle) :: open end type file_handle abstract interface subroutine open_file(handle) import class(file_handle), intent(inout) :: handle end subroutine open_file end interface S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
23 Finalization If your data type requires specific cleanup upon deallocation, you can define your own method with the final keyword: type, extends(psb_d_ell_sparse_mat) :: psb_d_elg_sparse_mat type(c_ptr) :: devicemat = c_null_ptr final :: d_elg_finalize end type psb_d_elg_sparse_mat... subroutine d_elg_finalize(a) use elldev_mod implicit none type(psb_d_elg_sparse_mat), intent(inout) :: a if (c_associated(a%devicemat)) & & call freeelldevice(a%devicemat) a%devicemat = c_null_ptr end subroutine d_elg_finalize S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
24 Style guidelines 1 Write code that comments itself: type(gas) :: air real, parameter :: viscosity=1.52e-05! meters/sec if (.not.readfromdisk(air)) air = constructgas(viscosity) 2 Name all constants; 3 Make constants constant (parameter attribute); 4 Minimize global data; 5 Make global data constant; 6 Provide global type parameters, including precision specification; S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
25 Style guidelines 7 Provide (conditional) debugging; 8 Declare INTENT for all arguments; 9 Avoid side effects, especially in FUNCTION 10 Make components PRIVATE 11 Use indentation (consistently) 12 Always prevent implicit typing S. Filippone (SATM) Modern Fortran OO Features IT4I, Ostrava, / 25
Fortran classes and data visibility
Fortran classes and data visibility Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-ncsa/4.0/deed.en_us
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationOops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:
Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Abstraction Encapsulation Inheritance and Polymorphism Object-Oriented
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationObject Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia
Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing
More informationSubroutines and Functions
Subroutines and Functions Procedures: Subroutines and Functions There are two types of procedures: SUBROUTINE: a parameterized named sequence of code which performs a specific task and can be invoked from
More informationObject Oriented Programming. Solved MCQs - Part 2
Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What
More informationCPS 506 Comparative Programming Languages. Programming Language
CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support
More informationChapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language
Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented
More informationWelcome. Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at BST
Welcome Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at 15.00 BST Modern Fortran: F77 to F90 and beyond Adrian Jackson adrianj@epcc.ed.ac.uk @adrianjhpc Fortran Ancient History (1967)
More informationJava 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 informationLecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction
Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO
More informationITI 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 informationIntro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.
Intro to OOP - Object and class - The sequence to define and use a class in a program - How/when to use scope resolution operator - How/when to the dot operator - Should be able to write the prototype
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationChapter 5 Object-Oriented Programming
Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares
More informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
More informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship The "is-a" Relationship Object classification
More informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship Object classification is typically hierarchical.
More informationProgramming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur
Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module
More informationCMSC 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 informationITI 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 informationCGS 2405 Advanced Programming with C++ Course Justification
Course Justification This course is the second C++ computer programming course in the Computer Science Associate in Arts degree program. This course is required for an Associate in Arts Computer Science
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationContents. 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 informationPolymorphism. Zimmer CSCI 330
Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)
More informationC++ Inheritance and Encapsulation
C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members
More informationWhat 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 informationPOLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE
Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public
More informationPOLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors
POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More informationC++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming
More informationObject-Oriented Programming
Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object
More informationOOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.
OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every
More informationIntroduction to Modern Fortran
Introduction to Modern Fortran p. 1/?? Introduction to Modern Fortran Advanced Use Of Procedures Nick Maclaren nmm1@cam.ac.uk March 2014 Introduction to Modern Fortran p. 2/?? Summary We have omitted some
More informationProgramming, numerics and optimization
Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428
More informationAtelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.
marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.
More informationInheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017
OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading
More informationObject 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 informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More informationMore C++ : Vectors, Classes, Inheritance, Templates
Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit
More informationCS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms
CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()
More informationFortran Coding Standards and Style
Fortran Coding Standards and Style The Fortran Company Version 20160112 Copyright 2015-2016, The Fortran Company All rights reserved. Redistribution, with or without modification, is permitted provided
More information1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!
//Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new
More informationObject Oriented Programming with c++ Question Bank
Object Oriented Programming with c++ Question Bank UNIT-1: Introduction to C++ 1. Describe the following characteristics of OOP. i Encapsulation ii Polymorphism, iii Inheritance 2. Discuss function prototyping,
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationProgramming Exercise 14: Inheritance and Polymorphism
Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.
More informationMore C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com
More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes
More informationReview More Arrays Modules Final Review
OUTLINE 1 REVIEW 2 MORE ARRAYS Using Arrays Why do we need dynamic arrays? Using Dynamic Arrays 3 MODULES Global Variables Interface Blocks Modular Programming 4 FINAL REVIEW THE STORY SO FAR... Create
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationSRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR
SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name
More informationObject oriented programming. Encapsulation. Polymorphism. Inheritance OOP
OOP Object oriented programming Polymorphism Encapsulation Inheritance OOP Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes
More informationCompaq Interview Questions And Answers
Part A: Q1. What are the difference between java and C++? Java adopts byte code whereas C++ does not C++ supports destructor whereas java does not support. Multiple inheritance possible in C++ but not
More informationStackVsHeap SPL/2010 SPL/20
StackVsHeap Objectives Memory management central shared resource in multiprocessing RTE memory models that are used in Java and C++ services for Java/C++ programmer from RTE (JVM / OS). Perspectives of
More informationCS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE
CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate
More informationObject-Oriented Programming
- oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More information(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University
(12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables
More informationCMSC 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 informationKLiC C++ Programming. (KLiC Certificate in C++ Programming)
KLiC C++ Programming (KLiC Certificate in C++ Programming) Turbo C Skills: Pre-requisite Knowledge and Skills, Inspire with C Programming, Checklist for Installation, The Programming Languages, The main
More informationCLASSES AND OBJECTS IN JAVA
Lesson 8 CLASSES AND OBJECTS IN JAVA (1) Which of the following defines attributes and methods? (a) Class (b) Object (c) Function (d) Variable (2) Which of the following keyword is used to declare Class
More informationEvolution of Fortran. Presented by: Tauqeer Ahmad. Seminar on Languages for Scientific Computing
Evolution of Fortran Presented by: Seminar on Languages for Scientific Computing Outline (1) History of Fortran Versions FORTRAN I FORTRAN II FORTRAN III FORTRAN IV FORTRAN 66 FORTRAN 77 Evolution of FORTRAN
More informationLecture Notes on Programming Languages
Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered
More informationC++ Programming: Polymorphism
C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function
More informationINHERITANCE & 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 informationQUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?
QUIZ Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? Or Foo(x), depending on how we want the initialization
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationOverview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017
Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationDepartment of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List
More informationProgramming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017
Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)
More informationSoftware Development. Modular Design and Algorithm Analysis
Software Development Modular Design and Algorithm Analysis Data Encapsulation Encapsulation is the packing of data and functions into a single component. The features of encapsulation are supported using
More informationXII- COMPUTER SCIENCE VOL-II MODEL TEST I
MODEL TEST I 1. What is the significance of an object? 2. What are Keyword in c++? List a few Keyword in c++?. 3. What is a Pointer? (or) What is a Pointer Variable? 4. What is an assignment operator?
More informationCMSC202 Computer Science II for Majors
CMSC202 Computer Science II for Majors Lecture 14 Polymorphism Dr. Katherine Gibson Last Class We Covered Miscellaneous topics: Friends Destructors Freeing memory in a structure Copy Constructors Assignment
More informationCMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am
CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103
More informationVIRTUAL FUNCTIONS Chapter 10
1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions
More informationInheritance, Polymorphism and the Object Memory Model
Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationReusing this material
Modules Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-ncsa/4.0/deed.en_us
More informationChapter 10 :: Data Abstraction and Object Orientation
Chapter 10 :: Data Abstraction and Object Orientation Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier Chapter10_Data_Abstraction_and_Object_Orientation_4e 1 Object-Oriented
More informationPaul F. Dubois. X-Division.
Large-scale simulations with Fortran 95: An object-based approach Lesson 3 Types and objects X-Division 1 of 29 In our first two lessons, we have concentrated on arrays, modules, and derived types. It
More informationChapter 9 :: Data Abstraction and Object Orientation
Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it in
More informationDay 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 informationFramework Fundamentals
Questions Framework Fundamentals 1. Which of the following are value types? (Choose all that apply.) A. Decimal B. String C. System.Drawing.Point D. Integer 2. Which is the correct declaration for a nullable
More informationQUESTIONS FOR AVERAGE BLOOMERS
MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/
More informationFortran Bill Long, Cray Inc. 21-May Cray Proprietary
Fortran 2003 Bill Long, Cray Inc. 21-May-2004 Cray Proprietary Fortran 2003 Specification for Fortran 2003 (f03) is finished Standard should be official in September 569 pages including Appendices and
More informationCSE 307: Principles of Programming Languages
CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction
More informationQUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?
QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The
More informationLecturer: William W.Y. Hsu. Programming Languages
Lecturer: William W.Y. Hsu Programming Languages Chapter 9 Data Abstraction and Object Orientation 3 Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though
More informationSubprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu
1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized
More informationBasics of Object Oriented Programming. Visit for more.
Chapter 4: Basics of Object Oriented Programming Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra,
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationObject-Oriented Programming
iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 40 Overview 1 2 3 4 5 2 / 40 Primary OOP features ion: separating an object s specification from its implementation. Encapsulation: grouping related
More informationChapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter 12 OOP: Creating Object- Oriented Programs McGraw-Hill Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Objectives (1 of 2) Use object-oriented terminology correctly. Create
More informationOverloading, abstract classes, and inheritance
Overloading, abstract classes, and inheritance Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-ncsa/4.0/deed.en_us
More informationPreface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.
Preface to the Second Edition p. iii Preface to the First Edition p. vi Brief Contents p. ix Introduction to C++ p. 1 A Review of Structures p. 1 The Need for Structures p. 1 Creating a New Data Type Using
More informationCpt S 122 Data Structures. Course Review Midterm Exam # 2
Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm
More information