Fundamentals of Object Oriented Programming

Similar documents
Fundamentals of Object Oriented Programming

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

What is Inheritance?

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

Inheritance and Polymorphism

Class, Variable, Constructor, Object, Method Questions

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

C++ Important Questions with Answers

And Even More and More C++ Fundamentals of Computer Science

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Chapter 4 Java Language Fundamentals

CS313D: ADVANCED PROGRAMMING LANGUAGE

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Inheritance and Encapsulation. Amit Gupta

Object Orientated Analysis and Design. Benjamin Kenwright

COMP 202 Java in one week

Java Object Oriented Design. CSC207 Fall 2014

JAVA MOCK TEST JAVA MOCK TEST II

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Data Structures (list, dictionary, tuples, sets, strings)

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

Programming II (CS300)

What are the characteristics of Object Oriented programming language?

5.6.1 The Special Variable this

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Programming II (CS300)

Chapter 5 Object-Oriented Programming

Introduction to Programming Using Java (98-388)

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

PROGRAMMING LANGUAGE 2

Inheritance & Polymorphism

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

CS-202 Introduction to Object Oriented Programming

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

CS313D: ADVANCED PROGRAMMING LANGUAGE

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

COMP 110/L Lecture 20. Kyle Dewey

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Practice for Chapter 11

Inheritance (Outsource: )

Compaq Interview Questions And Answers

Core Java Syllabus. Overview

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Access and Non access Modifiers in Core Java Core Java Tutorial

Sri Vidya College of Engineering & Technology

Object oriented programming Concepts

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Exception Handling Generics. Amit Gupta

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Object-Oriented Programming

CS121/IS223. Object Reference Variables. Dr Olly Gotel

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

Ch02. True/False Indicate whether the statement is true or false.

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Advanced concurrent programming in Java Shared objects

Declarations and Access Control SCJP tips

Logistics. Final Exam on Friday at 3pm in CHEM 102

C++ Inheritance and Encapsulation

VALLIAMMAI ENGINEERING COLLEGE

TaxiBot New attributes Variables Math! TaxiBot

Subclassing, con.nued Method overriding, virtual methods, abstract classes/methods. COMP 401, Spring 2015 Lecture 9 2/19/2015

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Exercise: Singleton 1

Microsoft Visual Basic 2005: Reloaded

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Self-review Questions

CS 231 Data Structures and Algorithms, Fall 2016

FOR BEGINNERS 3 MONTHS

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

CLASSES AND OBJECTS IN JAVA

Packages. Examples of package names: points java.lang com.sun.security drawing.figures

CSE 142 Su 04 Computer Programming 1 - Java. Objects

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

Classes and Objects. COMP1400/INFS1609 Week 8. Monday, 10 September 12

15CS45 : OBJECT ORIENTED CONCEPTS

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

Lecture 18 Tao Wang 1

Inheritance. Transitivity

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Object Oriented Programming with Java. Unit-1

STRUCTURING OF PROGRAM

I Wish I Knew How To. Begin Object Oriented Programming With Xojo. By Eugene Dakin. July 2015 Edition (1.0)

SRM INSTITUTE OF SCIENCE & TECHNOLOGY Faculty of Science and Humanities Department of Computer Science UNIT I - INTRODUCTION TO JAVA

Introduction to Computer Science I

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Software Design and Analysis for Engineers

1 Shyam sir JAVA Notes

CS 61B Discussion 4: Inheritance Fall 2018

Java Training JAVA. Introduction of Java

Inheritance, and Polymorphism.

QUESTIONS FOR AVERAGE BLOOMERS

Chapter 4 Defining Classes I

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Lecture 02, Fall 2018 Friday September 7

Basic Object-Oriented Concepts. 5-Oct-17

Transcription:

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of Technology Roorkee Roorkee 247 667 balarfcs@iitr.ac.in https://sites.google.com/site/balaiitr/

Access modifiers in JAVA The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class. There are 4 types of java access modifiers: private default protected public There are many non-access modifiers such as static, abstract, synchronized, native, volatile, transient etc. Here, we will learn access modifiers. 2

private access modifier The private access modifier is accessible only within class. https://ideone.com/4n9apl 3

Public Access Modifier https://ideone.com/0kmsoi 4

Public Access Modifier https://ideone.com/3s8mkk 5

Method overriding https://ideone.com/hobygb 6

Run Time Polymorphism Example 1 https://ideone.com/0chtnk 7

Example 2 https://ideone.com/l1qekz 8

Example 2, line no. 19 Here, even though b is a type of Animal it runs the move method in the Dog class. The reason for this is: In compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object. Hence, in this example, the program will compile properly since Animal class has the method move. Then, at the runtime, it runs the method specific for that object. 9

Example 3 https://ideone.com/6tydve 10

Using the super keyword: https://ideone.com/0wbdks 11

Runtime polymorphism can't be achieved by data members https://ideone.com/o4gb1v 12

Runtime Polymorphism https://ideone.com/kqt9tl 13

Run time polymorphism Find the output of https://ideone.com/ykjqou 14

Abstract Class A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body). Before learning java abstract class, let's understand the abstraction in java first. 15

Abstraction Abstraction is a process of hiding the implementation details and showing only functionality to the user. SMS example Laundry example by Steve Jobs 16

Interview with Steve Jobs Here, in an excerpt from a 1994 Rolling Stone interview, Steve Jobs explains what object-oriented programming is- Jeff Goodell: Would you explain, in simple terms, exactly what object-oriented software is? Steve Jobs: Objects are like people. They re living, breathing things that have knowledge inside them about how to do things and have memory inside them so they can remember things. And rather than interacting with them at a very low level, you interact with them at a very high level of abstraction, like we re doing right here. 17

Here s an example: If I m your laundry object, you can give me your dirty clothes and send me a message that says, Can you get my clothes laundered, please. I happen to know where the best laundry place in San Francisco is. And I speak English, and I have dollars in my pockets. So I go out and hail a taxicab and tell the driver to take me to this place in San Francisco. I go get your clothes laundered, I jump back in the cab, I get back here. I give you your clean clothes and say, Here are your clean clothes. 18

You have no idea how I did that. You have no knowledge of the laundry place. Maybe you speak French, and you can t even hail a taxi. You can t pay for one, you don t have dollars in your pocket. Yet I knew how to do all of that. And you didn t have to know any of it. All that complexity was hidden inside of me, and we were able to interact at a very high level of abstraction. That s what objects are. They encapsulate complexity, and the interfaces to that complexity are high level. Source: https://www.quora.com/what-is-object-orientedprogramming/answer/amogh-talpallikar 19

Ways to achieve Abstraction There are two ways to achieve abstraction in java Abstract class (0 to 100%) Interface (100%) 20

21