Classes, objects, methods and properties
|
|
- Kimberly Baker
- 5 years ago
- Views:
Transcription
1 Learning Object 1. African Virtual University Template for extracting a learning object Main Learning Objective Nature of learning object Key concept (s) Source Module information Access source module Extracted by To be able to create classes and objects using Java. A sub-topic CLASSES AND OBJECTS Module Title: Object Oriented Programming Code; CS Author: Lucy Gitau To be Provided by the AVU Lucy Gitau Date 27 th April 2016 Copy and Paste the Learning Object here Classes, objects, methods and properties Object-oriented programming is a programming style in which it is customary to group all of the variables and functions of a particular topic into a single class. Object-oriented programming is considered to be more advanced and efficient than the procedural style of programming. This efficiency stems from the fact that it supports better code organization, provides modularity, and reduces the need to repeat ourselves. However, we may still prefer the procedural style in small and simple projects. But, as our projects grow in complexity, we are better off using the object oriented style. With this tutorial, we are going to take our first steps into the world of object oriented programming by learning the most basic terms in the field: classes 1
2 objects methods properties learning objectives: How to create classes? How to add properties to a class? How to create objects from a class? How to get and set the objects' properties? How to add methods to a class? How to create classes? In order to create a class, we group the code that handles a certain topic into one place. For example, we can group all of the code that handles the users of a blog into one class, all of the code that is involved with the publication of the posts in the blog into a second class, and all the code that is devoted to comments into a third class. To name the class, it is customary to use a singular noun that starts with a capital letter. For example, we can group a code that handles users into a User class, the code that handles posts into a Post class, and the code that is devoted to comments into a Comment class. For the example given below, we are going to create a Car class into which we will group all of the code which has something to do with cars class Car { // The code We declare the class with the class keyword. We write the name of the class and capitalize the first letter. If the class name contains more than one word, we capitalize each word. This is known as upper camel case. For example, JapaneseCars, AmericanIdol, EuropeTour, etc. We circle the class body within curly braces. Inside the curly braces, we put our code. How to add properties to a class? We call properties to the variables inside a class. Properties can accept values like strings, integers, and booleans (true/false values), like any other variable. Let's add some properties to the Car class class Car { 2
3 public $comp; public $color = 'beige'; public $hassunroof = true; We put the public keyword in front of a class property. The naming convention is to start the property name with a lower case letter. If the name contains more than one word, all of the words, except for the first word, start with an upper case letter. For example, $color or $hassunroof. A property can have a default value. For example, $color = 'beige'. We can also create a property without a default value. See the property $comp in the above example. How to create objects from a class? We can create several objects from the same class, with each object having its own set of properties. In order to work with a class, we need to create an object from it. In order to create an object, we use the new keyword. For example: 1$bmw = new Car (); We created the object $bmw from the class Car with the new keyword. The process of creating an object is also known as instantiation. We can create more than one object from the same class. 1 2$bmw = new Car (); $mercedes = new Car (); In fact, we can create as many objects as we like from the same class, and then give each object its own set of properties. Objects, what are they good for? While in the procedural style of programming, all of the functions and variables sit together in the global scope in a way that allows their use just by calling their name, the use of classes makes anything inside the classes hidden from the global scope. That's because the code inside the classes is encapsulated within the class scope, outside the reach of the global scope. So, we need a way to allow the code from the global scope to use the code within the class, and we do this by creating objects from a class. I say objects, and not object, because we can create as many objects as we would like from the same class and they all will share the class's methods and properties. See the image below: 3
4 From the same Car class, we created three individual objects with the name of: Mercedes, Bmw, and Audi. Although all of the objects were created from the same class and thus have the class's methods and properties, they are still different. This is not only, because they have different names, but also because they may have different values assigned to their properties. For example, in the image above, they differ by the color property - the Mercedes is green while the Bmw is blue and the Audi is orange. Note: A class holds the methods and properties that are shared by all of the objects that are created from it. Although the objects share the same code, they can behave differently because they can have different values assigned to them. How to get an object's properties? Once we create an object, we can get its properties. For example: 1 2echo $bmw -> color; echo $mercedes -> color; In order to get a property, we write the class name, and then dash greater than (->), and then the property name. Note that the property name does not start with the $ sign; only the object name starts with a $. Result: beige beige 4
5 How to set the object's properties? In order to set an object property, we use a similar approach. For example, in order to set the color to 'blue' in the bmw object: 1$bmw -> color = 'blue'; and in order to set the value of the $comp property for both objects: 1 2$bmw -> comp = "BMW"; $mercedes -> comp = "Mercedes Benz"; Once we set the value of a property, we can get its value. In order to get the color of the $bmw object, we use the following line of code: 1echo $bmw -> color; Result: blue We can also get the company name and the color of the second car object. 1 2echo $mercedes -> color; echo $mercedes -> comp; Result: Mercedes Benz beige How to add methods to a class? The classes most often contain functions. A function inside a class is called a method. Here we add the method hello() to the class with the prefix public class Car { public $comp; public $color = 'beige'; public $hassunroof = true; public function hello() { return "beep"; We put the public keyword in front of a method. 5
6 The naming convention is to start the function name with a lower case letter. If the name contains more than one word, all of the words, except for the first word, start with an upper case letter. For example, hellouser() or flypanam(). We can approach the methods similar to the way that we approach the properties, but we first need to create at least one object from the class $bmw = new Car (); $mercedes = new Car (); echo $bmw -> hello(); echo $mercedes -> hello(); Result: beep beep Here is the full code that we have written during this tutorial: // Declare the class class Car { // properties public $comp; public $color = 'beige'; public $hassunroof = true; // method that says hello public function hello() { return "beep"; // Create an instance $bmw = new Car (); $mercedes = new Car (); // Get the values echo $bmw -> color; // beige echo "<br />"; echo $mercedes -> color; // beige echo "<hr />"; // Set the values $bmw -> color = 'blue'; $bmw -> comp = "BMW"; $mercedes -> comp = "Mercedes Benz"; // Get the values again echo $bmw -> color; // blue echo "<br />"; echo $mercedes -> color; // beige echo "<br />"; echo $bmw -> comp; // BMW echo "<br />"; echo $mercedes -> comp; // Mercedes Benz 6
7 echo "<hr />"; // Use the methods to get a beep echo $bmw -> hello(); // beep echo "<br />"; echo $mercedes -> hello(); // beep Conclusion We have learnt about classes and objects that can be created out of them. Learning object 2 Main Learning Objective Nature of learning object Key concept (s) Source Module information Access source module Extracted by To distinguish between inheritance and polymorphism. Designed summary Inheritance and polymorphism Module Title: Object Oriented Programming Code; CS Author: Lucy Gitau To be Provided by the AVU Lucy Gitau Date 27 th April 2016 Copy and Paste the Learning Object here Code of Polymorphism vs Inheritance in Java 7
8 Below is a code illustrating How Inheritance and Polymorphism works. In Java, polymorphism is type based, in order to write polymorphic code, you need to create a Type hierarchy, which is achieved using Inheritance. In this example, we have abstract class to represent a Connection and we have two sub-classes TCP and UDP. All three are related to each other via Inheritance, Connection is Parent while TCP and UDP are Child classes. Now any code, which is based upon Connection will be polymorphic and can behave differently based upon whether actual connection is of type TCP or UDP. This Polymorphism magic is constructed by method overriding in Java, but its the principle of programming for interfaces than implementation, which motivates to write polymorphic code. Why you should write Polymorphic code? Simple to be flexible, to accommodate change and to take advantage of evolution on later stage of development. A static code is fixed when written, but a Polymorphic code can evolve. public class Test { public static void main(string args[]) { Connection connection = new TCP(); connection.connect(); /** * Base class to represent a Connection. */ public abstract class Connection{ protected String data; public void connect(){ System.out.println("Connecting...") public void inputdate(string data){ this.data = data; public class TCP extends Connection { 8
9 @Override public void connect() { System.out.println("Connection reliably but slow.."); public class UDP extends Connection public void connect(){ System.out.println("Connecting fast but no guarantee of data delivery"); Output: Connection reliably but slow.. In short here are key difference between Polymorphism and Inheritance in Java : 1) Inheritance defines father-son relationship between two classes, While Polymorphism take advantage of that relationship to add dynamic behaviour in your code. 2) Inheritance is meant for code reuse, initial idea is to reuse what is written inside Parent class and only write code for new function or behaviour in Child class. On the other hand Polymorphism allows Child to redefine already defined behaviour inside parent class. Without Polymorphism it's not possible for a Child to execute its own behaviour while represented by a Parent reference variable, but with Polymorphism he can do that. 3) Polymorphism helps tremendously during Maintenance. In fact many object oriented design principles are based on Polymorphism e.g. programming for interface then implementation, which advocates to use interface everywhere in your code, to represent variable, in method parameters, in return type of method etc; so that code can take advantage of polymorphism and do more than what was expected it to do during writing. 4) Java doesn't allow multiple inheritance of classes, but allows multiple inheritance of Interface, which is actually require to implement Polymorphism. For example a Class can be Runnable, Comparator and Serializable at same time, because all three are interfaces. This makes them to pass around in code e.g. you can pass instance of this class to a method which accepts Serializable, or to Collections.sort() which accepts a Comparator. 9
10 5) Both Polymorphism and Inheritance allow Object oriented programs to evolve. For example, by using Inheritance you can define new user types in an Authentication System and by using Polymorphism you can take advantage of already written authentication code. Since, Inheritance guarantees minimum base class behaviour, a method depending upon super class or super interface can still accept object of base class and can authenticate it. 6) In UML diagram, Inheritance is represented using arrows, pointing towards Parent class. For example in this diagram, AbstractPerson is Parent class for Employee, Manager and CustomerContact class. Read more: Inheritance-java-oops.html#ixzz470oaJSpF learning object 3 Main Learning Objective Nature of learning object Key concept (s) Source Module information Access source module Extracted by To enable students to distinguish between procedural and object oriented programming Designed summary Differences between Procedural and Object Oriented Programming Module Title: Object Oriented Programming Code; CS Author: Lucy Gitau To be Provided by the AVU Lucy Gitau Date 27 th April
11 Copy and Paste the Learning Object here In this particular article we will learn about difference between Object Oriented Programming (OOP) and procedural programming. Let s learn by making some key differences: Division Of Program In procedural programming a program is divided into small functions while in oop it is divided into objects. Importance In procedural programming importance is not given to data but to procedure. But in oop importance is given to data rather than functions. Because in oop it works well with real world objects. Approach In procedural programming top down approach is followed but in oop bottom up approach is followed. Access Specifiers In procedural programming no access specifiers are used. But in oop different type of specifiers are used for different level of data protection. Data Moving 11
12 In procedural program data can move freely from function to function. But in oop data can only move from member functions. Data Access In procedural programming most of the time global data can be used. So all functions of program uses global data. In oop public or private access specifiers are used to control the data access. Data Hiding In procedural programming no particular method is used for data hiding. And therefore it is less secure. A particular method is used for data hiding in oop so it is more secure. Overloading Overloading is not possible in procedural programming. Overloading is possible in oop in the form of function overloading and overloading operator. Examples Examples of procedure oriented are c, vb, fortran. And examples of object oriented are Java, C#.Net etc. So all the above are key difference between procedural and object oriented programming. Learning object 4 Main Learning Objective Nature of learning object Key concept (s) Source Module information Access source module Extracted by To distinguish between visibility types in object oriented programming Case scenario for class student To be able to assign appropriate visibility to variables/ methods in a class/ object Module Title: Object Oriented Programming Code; CS Author: Lucy Gitau To be Provided by the AVU Lucy Gitau Date 27 th April 2016 Copy and Paste the Learning Object here 12
13 Learning Object 5 Main Learning Objective Nature of learning object Key concept (s) Source Module information Access source module Extracted by To be able to create simple desk top applications Introduction to GUI programming CLASSES AND OBJECTS Module Title: Object Oriented Programming Code; CS Author: Lucy Gitau To be Provided by the AVU Lucy Gitau Date 6 th April 2016 Introduction to object oriented programming with java, 5th edition Wu, C. Thomas,
Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L
Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive
More informationObject oriented programming Concepts
Object oriented programming Concepts Naresh Proddaturi 09/10/2012 Naresh Proddaturi 1 Problems with Procedural language Data is accessible to all functions It views a program as a series of steps to be
More informationCOMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal
COMSC-051 Java Programming Part 1 Part-Time Instructor: Joenil Mistal Chapter 4 4 Moving Toward Object- Oriented Programming This chapter provides a provides an overview of basic concepts of the object-oriented
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 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 informationPrinciples of Object Oriented Programming. Lecture 4
Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance
More informationENCAPSULATION. private, public, scope and visibility rules. packages and package level access.
ENCAPSULATION private, public, scope and visibility rules. packages and package level access. Q. Explain the term Encapsulation with an example? Ans: The wrapping up to data and methods into a single units
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 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 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 informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
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 informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
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 informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University OOP Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation Inheritance
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 informationCREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed
CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationBASIC CONCEPT OF OOP
Chapter-6 BASIC CONCEPT OF OOP Introduction: Object oriented programmingg is the principle of design and development of programs using modular approach. Object oriented programmingg approach provides advantages
More informationObject Oriented Programming with Java
Object Oriented Programming with Java What is Object Oriented Programming? Object Oriented Programming consists of creating outline structures that are easily reused over and over again. There are four
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract
More informationObject-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)
Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Sung Hee Park Department of Mathematics and Computer Science Virginia State University September 18, 2012 The Object-Oriented Paradigm
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are
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 information7. C++ Class and Object
7. C++ Class and Object 7.1 Class: The classes are the most important feature of C++ that leads to Object Oriented programming. Class is a user defined data type, which holds its own data members and member
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 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 informationObject Oriented Programming
Object Oriented Programming Digital Urban Visualization. People as Flows. 10.10.2016 ia zuend@arch.ethz.ch treyer@arch.ethz.ch chirkin@arch.ethz.ch Object Oriented Programming? Pertaining to a technique
More informationObject Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani
Object Oriented Programming C++ 6 th Sem, A Div 2018-19 Ms. Mouna M. Naravani Object Oriented Programming (OOP) removes some of the flaws encountered in POP. In OOPs, the primary focus is on data rather
More informationObject Oriented Software Development CIS Today: Object Oriented Analysis
Object Oriented Software Development CIS 50-3 Marc Conrad D104 (Park Square Building) Marc.Conrad@luton.ac.uk Today: Object Oriented Analysis The most single important ability in object oriented analysis
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 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 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 informationObject-Oriented Programming (OOP) Fundamental Principles of OOP
Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is
More informationObject Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance
CS257 Computer Science I Kevin Sahr, PhD Lecture 10: Inheritance 1 Object Oriented Features For a programming language to be called object oriented it should support the following features: 1. objects:
More informationOO Techniques & UML Class Diagrams
OO Techniques & UML Class Diagrams SE3A04 Tutorial Jason Jaskolka Department of Computing and Software Faculty of Engineering McMaster University Hamilton, Ontario, Canada jaskolj@mcmaster.ca October 17,
More informationIT101. Inheritance, Encapsulation, Polymorphism and Constructors
IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable
More informationInheritance -- Introduction
Inheritance -- Introduction Another fundamental object-oriented technique is called inheritance, which, when used correctly, supports reuse and enhances software designs Chapter 8 focuses on: the concept
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 informationReviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Things to Review Review the Class Slides: Key Things to Take Away Do you understand
More informationChapter 15: Object Oriented Programming
Chapter 15: Object Oriented Programming Think Java: How to Think Like a Computer Scientist 5.1.2 by Allen B. Downey How do Software Developers use OOP? Defining classes to create objects UML diagrams to
More informationObject-Oriented Software Engineering. Chapter 2: Review of Object Orientation
Object-Oriented Software Engineering Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized around the notion of procedures Procedural abstraction
More informationJava Basics. Object Orientated Programming in Java. Benjamin Kenwright
Java Basics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Java Concepts Syntax, Grammar, Formatting, Introduce Object-Orientated Concepts Encapsulation, Abstract Data, OO Languages,
More informationJAVA: A Primer. By: Amrita Rajagopal
JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently
More informationProgramming in C# Inheritance and Polymorphism
Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 17 Inheritance Overview Problem: Can we create bigger classes from smaller ones without having to repeat information? Subclasses: a class inherits
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 informationProgramming I. Course 9 Introduction to programming
Programming I Course 9 Introduction to programming What we talked about? Modules List Comprehension Generators Recursive Functions Files What we talk today? Object Oriented Programming Classes Objects
More informationDay 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University
Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays
More informationIntroduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT). Encapsulation OOP: Introduction 1 Pure Object-Oriented Languages Five rules [Source: Alan Kay]: Everything in
More informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationObject-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized
More informationSTUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming
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 informationPART A : MULTIPLE CHOICE Circle the letter of the best answer (1 mark each)
PART A : MULTIPLE CHOICE Circle the letter of the best answer (1 mark each) 1. An example of a narrowing conversion is a) double to long b) long to integer c) float to long d) integer to long 2. The key
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 informationObject Oriented Programming
Object Oriented Programming Ray John Pamillo 1/27/2016 1 Nokia Solutions and Networks 2014 Outline: Brief History of OOP Why use OOP? OOP vs Procedural Programming What is OOP? Objects and Classes 4 Pillars
More information9 Working with the Java Class Library
9 Working with the Java Class Library 1 Objectives At the end of the lesson, the student should be able to: Explain object-oriented programming and some of its concepts Differentiate between classes and
More informationIntroduction to OOP. Procedural Programming sequence of statements to solve a problem.
Introduction to OOP C++ - hybrid language improved and extended standard C (procedural language) by adding constructs and syntax for use as an object oriented language. Object-Oriented and Procedural Programming
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 10 Creating Classes and Objects Objectives After studying this chapter, you should be able to: Define a class Instantiate an object from a class
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 2/12/2018. Which statement is correct about overriding private methods in the super class?
Which statement is correct about overriding private methods in the super class? Peer Instruction Polymorphism Please select the single correct answer. A. Any derived class can override private methods
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationMultiple Inheritance, Abstract Classes, Interfaces
Multiple Inheritance, Abstract Classes, Interfaces Written by John Bell for CS 342, Spring 2018 Based on chapter 8 of The Object-Oriented Thought Process by Matt Weisfeld, and other sources. Frameworks
More information(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days
Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented
More informationObject Orientated Analysis and Design. Benjamin Kenwright
Notation Part 2 Object Orientated Analysis and Design Benjamin Kenwright Outline Review What do we mean by Notation and UML? Types of UML View Continue UML Diagram Types Conclusion and Discussion Summary
More informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationIntroduction to Inheritance
Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationObject Oriented Programming: Based on slides from Skrien Chapter 2
Object Oriented Programming: A Review Based on slides from Skrien Chapter 2 Object-Oriented Programming (OOP) Solution expressed as a set of communicating objects An object encapsulates the behavior and
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005 Objectives After studying this chapter, you should be able to: Explain the history of programming languages
More informationInheritance and Substitution (Budd chapter 8, 10)
Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various
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 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 informationGet Unique study materials from
Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code
More informationArrays Classes & Methods, Inheritance
Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value
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 informationCOURSE 2 DESIGN PATTERNS
COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract
More informationCSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation
CSE 452: Programming Languages Data Abstraction and Object-Orientation Previous Lecture Abstraction Abstraction is the elimination of the irrelevant and the amplification of the essential Robert C Martin
More informationDay 2. COMP 1006/1406A Summer M. Jason Hinek Carleton University
Day 2 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda a quick look back (Monday s class) assignments a1 is due on Monday a2 will be available on Monday and is due the following
More informationCS 251 Intermediate Programming Inheritance
CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?
More informationThe high-level language has a series of primitive (builtin) types that we use to signify what s in the memory
Types and Variables We write code like: int x = 512; int y = 200; int z = x+y; The high-level language has a series of primitive (builtin) types that we use to signify what s in the memory The compiler
More informationObject Oriented Programming in C#
Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create
More informationFinal Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings
More informationInheritance and Polymorphism
Inheritance and Polymorphism Inheritance (Continued) Polymorphism Polymorphism by inheritance Polymorphism by interfaces Reading for this lecture: L&L 10.1 10.3 1 Interface Hierarchies Inheritance can
More informationSEEM4570 System Design and Implementation Lecture 09 Object Oriented Programming
SEEM4570 System Design and Implementation Lecture 09 Object Oriented Programming Programming In general, there are two kinds of programming: Procedural Programming Also known as Imperative Programming
More informationChapter 5: Classes and Objects in Depth. Information Hiding
Chapter 5: Classes and Objects in Depth Information Hiding Objectives Information hiding principle Modifiers and the visibility UML representation of a class Methods Message passing principle Passing parameters
More information1. Write two major differences between Object-oriented programming and procedural programming?
1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:
More informationChapter 5. Inheritance
Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super
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 informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationMidterm Exam CS 251, Intermediate Programming March 6, 2015
Midterm Exam CS 251, Intermediate Programming March 6, 2015 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationLesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10B Class Design By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Encapsulation Inheritance and Composition is a vs has a Polymorphism Information Hiding Public
More informationLecture 7: Classes and Objects CS2301
Lecture 7: Classes and Objects NADA ALZAHRANI CS2301 1 What is OOP? Object-oriented programming (OOP) involves programming using objects. An object represents an entity in the real world that can be distinctly
More informationCS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes
CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented
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 informationNotes on Chapter Three
Notes on Chapter Three Methods 1. A Method is a named block of code that can be executed by using the method name. When the code in the method has completed it will return to the place it was called in
More information