Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Size: px
Start display at page:

Download "Yosemite National Park, California. CSE 114 Computer Science I Inheritance"

Transcription

1 Yosemite National Park, California CSE 114 Computer Science I Inheritance

2 Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice HAS-A Die

3 Inheritance One class can be derived from another class inherits its instance variables and methods child class -----> parent class IS-A subclass class derived class base class Any instance variable or method that is inherited by a subclass does not need to be redefined in the subclass.

4 Why use Inheritance? Customize classes (from the JDK or your own) Benefits: Don t have to re-write code Abstraction the JDK has many classes to customize, especially for GUIs Use methods and variables of fully tested classes Code in super classes can be used by a limitless number of subclasses Making changes to common properties is easier just change the parent class

5 Inheritance is powerful And the real reason? Why? Code written today can call methods written 10 years from now Huh? That s due to inheritance & polymorphism, more on this next lecture

6 Inheritance Syntax public class ChildClass extends ParentClass { // instance variables for Child only // methods for Child only ChildClass now contains all instance variables and methods defined above, as well as those defined inside ParentClass

7 How to organize classes using Inheritance Determine what data you need to store. For example, for storing student and employee data: Student data: name, age, GPA Employee data: name, age, salary Divide up your classes according to state since Students and Employees store different data, use separate classes Pool common data into a common parent class Person data: name, age Have Student and Employee classes customize Person

8 Example: Parent Class: Person public class Person { private String name; private int age; // constructor public Person(String initname) { age = 0; // just born name = initname; // accessor method public String getname() { return name; // accessor method public int getage() { return age; // mutator method public void setage(int newage) { if (newage < 0) age = 0; else age = newage;

9 Example: Child (Sub-)Class: Student public class Student extends Person { private double gpa; // constructor for a Student public Student(String initname) { super(initname); gpa = 0.0; Means Student inherits all instance variables and methods from Person Runs Person s constructor public double getgpa() { return gpa; public void setgpa(double newgpa) { if (newgpa < 0.0 newgpa > 4.0) gpa = 0.0; else gpa = newgpa;

10 Example: Child (Sub-)Class: Employee public class Employee extends Person { private int salary; // constructor for an Employee public Employee(String initname) { super(initname); salary = 0; public int getsalary() { return salary; public void setsalary(int newsalary) { if (newsalary < 0 newsalary > ) salary = 0; else salary = newsalary;

11 How much memory do they need? When we construct a Student? age: 4 bytes name: 4 bytes for String memory address more memory for String data itself of course gpa: 8 bytes How about an Employee? age: 4 bytes name: 4 bytes for String memory address salary: 4 bytes

12 Example: Using all three classes public class PeopleTester { public static void main(string[] args) { Person moe = new Person("Moe Stooge"); Student larry = new Student("Larry Stooge"); Employee curly = new Employee("Curly Stooge"); moe.setage(106); moe.setgpa(2.2); moe.setsalary(100000); // LEGAL? // LEGAL? // LEGAL? YES! NO! NO! larry.setage(101); larry.setgpa(1.2); larry.setsalary(50000); // LEGAL? // LEGAL? // LEGAL? YES! YES! NO! curly.setage(100); curly.setgpa(0.5); curly.setsalary(25000); // LEGAL? // LEGAL? // LEGAL? NO! YES! YES!

13 Inheritance: public vs. private Inherited methods are accessible by the derived class if they are public or protected. Inherited instance variables are not directly accessible by the derived class if they are private. Use public accessor/mutator methods of parent class instead. For example, if we added a clear method inside Student: public void clear() { age = 0; gpa = 0.0; ILLEGAL public void clear() { setage(0); gpa = 0.0; LEGAL private methods of a base class are not accessible by the derived class.

14 Inheritance: super() and this() super() runs base (parent) class' constructor Must be first statement in a derived class' constructor If it is left out, super() is still executed using the base class' default constructor (with no parameters) this() runs a class' own constructor Used on first line of another constructor May pass parameters to this() as long as they correspond to parameters for another constructor For example, if we added a new constructor for Student: public Student(String initname, double initgpa) { this(initname); gpa = initgpa; Runs the previously defined Student constructor

15 Inheritance: Overriding Methods A method is overridden if it is redefined in a derived class (child class) using the same method Signature. Person (parent class): public void reset() { age = 0; Student (child class): public void reset() { setage(0); gpa = 0.0; OR, Calling an overridden method: public void reset() { super.reset(); gpa = 0.0; What happens if you forget super?

16 Method Summary protected Object The Object class Every class is a subclass of the java.lang.object class, even if not specified directly. clone() Creates and returns a copy of this object. boolean equals(object obj) Indicates whether some other object is "equal to" this one. String tostring() Returns a string representation of the object. Automatically Called on an object whenever it is placed inside System.out.print( The 3 methods above are overridden nearly every time a new class is defined. The Object class also contains 8 other methods we won t use

17 Overriding tostring() method Example public class Person { public String tostring() { return name + ", age " + age; public class Student extends Person { public String tostring() { return super.tostring() + ", GPA: " + gpa; public class Employee extends Person { public String tostring() { return super.tostring() + ", Salary: $" + salary;

18 Printing using tostring() public class StoogePrinter { public static void main(string[] args) { Person moe = new Person("Moe Stooge"); Student larry = new Student("Larry Stooge"); Employee curly = new Employee("Curly Stooge"); System.out.println(moe.toString()); System.out.println(larry.toString()); System.out.println(curly); OUTPUT: Moe Stooge, age 0 Larry Stooge, age 0, GPA: 0.0 Curly Stooge, age 0, Salary: $0

19 public class Course { public int coursenumber = 114; public class Classroom { public String building = "Javits"; public int roomnumber = 100; public String tostring() { return building + roomnumber; Exercise to try at home public class LectureHall extends Classroom { public int capacity = 650; public class ToStringExample { public static void main(string[] args) { System.out.println(new Course()); System.out.println(new Classroom()); System.out.println(new LectureHall()); What output do you get?

20 Multiple Inheritance A class may extend only 1 class, however, when it does so it also inherits all methods and variables that the parent class has already inherited Example: public class Instructor extends Employee { private String dept; public Instructor(String initname) { super(initname); dept = "None Assigned"; public String getdept() { return dept; public void setdept(string newdept) { dept = newdept; public String tostring() { return super.tostring() + ", Dept: " + dept; public static void main(string[] args) { Instructor me = new Instructor("Richard McKenna"); System.out.println(me); OUTPUT: Richard McKenna, age 0, Salary: $0, Dept: None Assigned

21 Inheritance Diagrams Think of an inheritance diagram as a family tree for classes, except for a couple of differences: A class may only have 1 immediate parent No criss-crossing in a class tree Every class has all the properties (state and behavior) of all of it s ancestors (so much for Darwinism) Student Person Employee Instructor A class may have any number of ancestors, in this case Instructor has 2.

22 Inheritance Diagrams family tree? The Town Drunk Mama Uncle Ernie Mary Joe Joe Bob Farmer s daughter across state line Old Man Up the Mountain Elvira Fat Irma Little Bob Cletus Mary Joe Elvis Selma Sue Danger: The family tree is crossing!

23 Inheritance Diagram Example Object Component A class may only have 1 immediate parent No criss-crossing in a class tree Container JComponent Window JPanel AbstractButton Frame JButton JFrame

24 Interfaces An interface is a collection of abstract methods that are defined by all classes that implement it. cannot be instantiated includes headers for the methods but no implementation generally used to force a class to implement certain methods public interface Clock { public void set(int hour, int minute); public String gettime(); public class Watch implements Clock { // CLASS DEFINITION FOR Watch GOES HERE // MUST define public methods set() and gettime()

STUDENT LESSON A11 Inheritance

STUDENT LESSON A11 Inheritance STUDENT LESSON A11 Inheritance Java Curriculum for AP Computer Science, Student Lesson A11 1 STUDENT LESSON A11 Inheritance INTRODUCTION: Inheritance, a major component of OOP, is a technique that will

More information

CS 335 Java Programming Inheritance

CS 335 Java Programming Inheritance CS 335 Java Programming Inheritance Java: Object-Oriented Programming Inheritance: superclasses and subclasses Polymorphism: abstract and concrete classes Dynamic binding Multiple inheritance via Interfaces

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

Java Programming Language

Java Programming Language Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and

More information

COMPSCI 125 Practice Final Exam (Summer 2012)

COMPSCI 125 Practice Final Exam (Summer 2012) COMPSCI 125 Practice Final Exam (Summer 2012) Time: 120 minutes Name : email address (for grade) : This exam has 13 questions, for a total of 200 points. Question Points Score 1 35 2 15 3 10 4 20 5 10

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Chapter 7. Inheritance. Inheritance Basics Programming with Inheritance Dynamic Binding and Polymorphism

Chapter 7. Inheritance. Inheritance Basics Programming with Inheritance Dynamic Binding and Polymorphism Chapter 7 Inheritance Inheritance Basics Programming with Inheritance Dynamic Binding and Polymorphism Chapter 7 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Principles of

More information

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword. http://www.tutorialspoint.com/java/java_inheritance.htm JAVA - INHERITANCE Copyright tutorialspoint.com Inheritance can be defined as the process where one class acquires the properties methodsandfields

More information

Inheritance, overloading and overriding

Inheritance, overloading and overriding Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Chapter 13 - Inheritance

Chapter 13 - Inheritance Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

More information

Self-test Java Programming

Self-test Java Programming Self-test Java Programming Document: e0883test.fm 22/01/2013 ABIS Training & Consulting P.O. Box 220 B-3000 Leuven Belgium TRAINING & CONSULTING INTRODUCTION TO THE SELF-TEST JAVA PROGRAMMING This test

More information

CHAPTER. Inheritance

CHAPTER. Inheritance CHAPTER 7 Inheritance 7.1 INHERITANCE BASICS 372 Derived Classes 373 Overriding a Method Definition 383 Pitfall: Overriding versus Overloading 383 The super Constructor 385 The this Constructor 386 Tip:

More information

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 This Week CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 School of Computer Science University of St Andrews Graham Kirby Alan Dearle More on Java classes Constructors Modifiers cdn.videogum.com/img/thumbnails/photos/commenter.jpg

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

CSE 1020 Introduction to Computer Science I A sample nal exam

CSE 1020 Introduction to Computer Science I A sample nal exam 1 1 (8 marks) CSE 1020 Introduction to Computer Science I A sample nal exam For each of the following pairs of objects, determine whether they are related by aggregation or inheritance. Explain your answers.

More information

Implementation Inheritance

Implementation Inheritance Implementation Inheritance Computer Science and Engineering College of Engineering The Ohio State University Lecture 12 Recall: Interface Inheritance void select (Person p) { //declared type of p is: //dynamic

More information

ICOM 4015: Advanced Programming

ICOM 4015: Advanced Programming ICOM 4015: Advanced Programming Lecture 10 Reading: Chapter Ten: Inheritance Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 10 Inheritance Chapter Goals To learn about inheritance To

More information

Chap 7 - Inheritance. An example from Zoology. An example from java.lang. Other terms from inheritance. parent. Mammal. child. Mouse. child.

Chap 7 - Inheritance. An example from Zoology. An example from java.lang. Other terms from inheritance. parent. Mammal. child. Mouse. child. Chap 7 - Inheritance An example from Zoology parent Mammal child child Mouse Elephant grandchild grandchild grandchild grandchild Field??? African Indian 1 2 An example from java.lang Other terms from

More information

Abstract Classes. 29 August 2016 OSU CSE 1

Abstract Classes. 29 August 2016 OSU CSE 1 Abstract Classes 29 August 2016 OSU CSE 1 The Real Story? Standard NaturalNumber- Kernel Comparable implements NaturalNumber implements NaturalNumber1L NaturalNumber2 29 August 2016 OSU CSE 2 The Real

More information

Object Oriented Programming (Part III)

Object Oriented Programming (Part III) Topic 7 Object Oriented Programming (Part III) LEARNING OUTCOMES By the end of this topic, you should be able to: 1. Describe the meaning of inheritance; 2. Differentiate between method overloading and

More information

CSC207 - Arrays, Inheritance, Generic Types

CSC207 - Arrays, Inheritance, Generic Types CSC207 - Arrays, Inheritance, Generic Types Ilir Dema Summer 2016 What is an array? An array is an arrangement of elements of the same type at equally spaced addresses in computer memory. Algonquin Radio

More information

(e) none of the above.

(e) none of the above. 1 The default value of a static integer variable of a class in Java is, (a) 0 (b) 1 (c) Garbage value (d) Null (e) -1 2 What will be printed as the output of the following program? public class testincr

More information

Advanced Data Structures

Advanced Data Structures C++ Advanced Data Structures Chapter 8: Advanced C++ Topics Zhijiang Dong Dept. of Computer Science Middle Tennessee State University Chapter 8: Advanced C++ Topics C++ 1 C++ Syntax of 2 Chapter 8: Advanced

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Facebook Twitter YouTube Google Plus Website Email

Facebook Twitter YouTube Google Plus Website Email PHP MySQL COURSE WITH OOP COURSE COVERS: PHP MySQL OBJECT ORIENTED PROGRAMMING WITH PHP SYLLABUS PHP 1. Writing PHP scripts- Writing PHP scripts, learn about PHP code structure, how to write and execute

More information

Construction of classes with classes

Construction of classes with classes (November 13, 2014 Class hierarchies 1 ) Construction of classes with classes Classes can be built on existing classes through attributes of object types. Example: I A class PairOfDice can be constructed

More information

Description of Class Mutation Mutation Operators for Java

Description of Class Mutation Mutation Operators for Java Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University

More information

Methods and Inheritance: Overriding

Methods and Inheritance: Overriding Methods and Inheritance: Overriding We might want to require that every Person can dance. But the way a Lecturer dances is not likely to be the same as the way a Student dances... Student overrides the

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

D06 PROGRAMMING with JAVA

D06 PROGRAMMING with JAVA Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch13 Inheritance PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for accompanying

More information

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism. Outline Inheritance Class Extension Overriding Methods Inheritance and Constructors Polymorphism Abstract Classes Interfaces 1 OOP Principles Encapsulation Methods and data are combined in classes Not

More information

Assignment # 2: Design Patterns and GUIs

Assignment # 2: Design Patterns and GUIs CSUS COLLEGE OF ENGINEERING AND COMPUTER SCIENCE Department of Computer Science CSc 133 Object-Oriented Computer Graphics Programming Spring 2014 John Clevenger Assignment # 2: Design Patterns and GUIs

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

Polymorphism II CMSC 202

Polymorphism II CMSC 202 Polymorphism II CMSC 202 Topics Constructors and polymorphism The clone method Abstract methods Abstract classes 10/2010 2 Constructors and Polymorphism A constructor for the base class is automatically

More information

Advanced Placement Computer Science. Main Tenants of OO Programming. Inheritance and Polymorphism. Nomenclature of Inheritance

Advanced Placement Computer Science. Main Tenants of OO Programming. Inheritance and Polymorphism. Nomenclature of Inheritance Advanced Placement Computer Science Inheritance and Polymorphism What s past is prologue. Don t write it twice write it once and reuse it. Bekki George James E. Taylor HS, Katy Main Tenants of OO Programming

More information

Abstract Data Types (ADTs) Basic Elements of an ADT. Translating an ADT into Code. Problem Magic! Solution. Class #26: Abstract Data Types. Data.

Abstract Data Types (ADTs) Basic Elements of an ADT. Translating an ADT into Code. Problem Magic! Solution. Class #26: Abstract Data Types. Data. Abstract Data Types (ADTs) Problem Magic! Solution Class #26: Abstract Data Types Software Design II (CS 220): M. Allen, 11 March 16! An ADT is like a sketch of a solution to a problem! The basic elements

More information

Software Development with UML and Java 2 SDJ I2, Spring 2010

Software Development with UML and Java 2 SDJ I2, Spring 2010 Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda week 7, 2010 Pakages Looking back Looking forward Packages Interfaces Page 1 Spring 2010 Download, Install/Setup 1. Java SE SDK (http://java.sun.com/javase/downloads)

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

EXPLICIT AND AUTOMATIC STRING CONVERSION IN JAVA

EXPLICIT AND AUTOMATIC STRING CONVERSION IN JAVA EXPLICIT AND AUTOMATIC STRING CONVERSION IN JAVA Data with other data types can be converted to String using explicit and automatic ways in Java. Explicit String conversion ways include: Use of the tostring()

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 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 and compile the java

More information

CMSC 206. Inheritance, Abstract Classes, and Interfaces

CMSC 206. Inheritance, Abstract Classes, and Interfaces CMSC 206 Inheritance, Abstract Classes, and Interfaces Class Reuse n We have seen how classes (and their code) can be reused with composition. An object has another object as one (or more) of its instance

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

Konzepte objektorientierter Programmierung

Konzepte objektorientierter Programmierung Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 3: Some More OO Languages Wintersemester 04/05 Agenda for Today 2 Homework Finish

More information

Moving from Java to C++

Moving from Java to C++ Moving from Java to C++ This appendix explains how to transfer your Java programming skills to a substantial subset of C++. This is necessary for students who take their first programming course in Java

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading: 9.1 The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale

More information

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism Polymorphism 1 Agenda What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism 2 What is & Why Polymorphism? 3 What is Polymorphism? Generally, polymorphism refers

More information

Java 101 primer: Composition and inheritance. Use composition to overcome the problem with inheritance

Java 101 primer: Composition and inheritance. Use composition to overcome the problem with inheritance Java 101 primer: Composition and inheritance Use composition to overcome the problem with inheritance BY JEFF FRIESEN, JAVAWORLD, OCTOBER 2015 In Java 101: Inheritance in Java, Part 1, you learned how

More information

Introduction to Algorithms and Data Structures

Introduction to Algorithms and Data Structures Introduction to Algorithms and Data Structures Lecture 5 Inheritance Inheritance and Derived Classes Inheritance is the process by which a new class is created from another class. The new class is called

More information

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be: Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

More information

Ch 7-1. Object-Oriented Programming and Classes

Ch 7-1. Object-Oriented Programming and Classes 2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

Inheritance. Classes and Subclasses Or Extending a Class

Inheritance. Classes and Subclasses Or Extending a Class Inheritance Classes and Subclasses Or Extending a Class 1 Inheritance: Introduction Reusability--building new components by utilising existing components- is yet another important aspect of OO paradigm.

More information

Web Development and Core Java Lab Manual V th Semester

Web Development and Core Java Lab Manual V th Semester Web Development and Core Java Lab Manual V th Semester DEPT. OF COMPUTER SCIENCE AND ENGINEERING Prepared By: Kuldeep Yadav Assistant Professor, Department of Computer Science and Engineering, RPS College

More information

CS193j, Stanford Handout #10 OOP 3

CS193j, Stanford Handout #10 OOP 3 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT) Encapsulation and information hiding Aggregation Inheritance and polymorphism OOP: Introduction 1 Pure Object-Oriented

More information

CSCU9T4: Object Modelling, principles of OO design and implementation

CSCU9T4: Object Modelling, principles of OO design and implementation CSCU9T4: Object Modelling, principles of OO design and implementation CSCU9T4 Spring 2016 1 What is Inheritance? Why use Inheritance? Discussion CSCU9T4 Spring 2016 2 Inheritance In inheritance, a subclass

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

CSE 303 Concepts and Tools for Software Development. Magdalena Balazinska Winter 2010 Lecture 19 Inheritance (virtual functions and abstract classes)

CSE 303 Concepts and Tools for Software Development. Magdalena Balazinska Winter 2010 Lecture 19 Inheritance (virtual functions and abstract classes) CSE 303 Concepts and Tools for Software Development Magdalena Balazinska Winter 2010 Lecture 19 Inheritance (virtual functions and abstract classes) Where We Are We have already covered the introduction

More information

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages

More information

c) Comments are areas of text ignored by the Java compiler.

c) Comments are areas of text ignored by the Java compiler. 1) Java applications a) A java application has a special method, called the main method, which is where the program will start. i) Each class can only have one main method. ii) You can tell eclipse which

More information

Design Patterns in Java

Design Patterns in Java Design Patterns in Java 2004 by CRC Press LLC 2 BASIC PATTERNS The patterns discussed in this section are some of the most common, basic and important design patterns one can find in the areas of object-oriented

More information

Singleton vs utility class

Singleton vs utility class Singleton vs utility class at first glance, the singleton pattern does not seem to offer any advantages to using a utility class i.e., a utility class with non-final static fields looks a lot like a single

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. For the question(s) below, assume values is an int array that is currently filled to capacity,

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT

More information

More About Classes: Instance Methods. Chapter 6

More About Classes: Instance Methods. Chapter 6 More About Classes: Instance Methods Chapter 6 Chapter Contents Chapter Objectives 6.1 Introductory Example: Modeling Temperatures 6.2 Designing a Class 6.3 Implementing Class Attributes 6.4 Implementing

More information

Course: Introduction to Java Using Eclipse Training

Course: Introduction to Java Using Eclipse Training Course: Introduction to Java Using Eclipse Training Course Length: Duration: 5 days Course Code: WA1278 DESCRIPTION: This course introduces the Java programming language and how to develop Java applications

More information

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: JAVA OBJECTS JAVA OBJECTS AND CLASSES Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: Polymorphism Inheritance

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

More information

2. Declare a pointer variable named ptr to an integer. ANSWER: int *ptr;

2. Declare a pointer variable named ptr to an integer. ANSWER: int *ptr; Chapter 9 Short Answer 1. A is the memory address of a variable. ANSWER: pointer 2. Declare a pointer variable named ptr to an integer. ANSWER: int *ptr; 3. In the statement cout

More information

Introduction to Algorithms and Data Structures

Introduction to Algorithms and Data Structures Introduction to Algorithms and Data Structures Lecture 6 Polymorphism and Abstract Classes Polymorphism Polymorphism allows the programmer to write several different methods with the same name. Up until

More information

TCP Sockets. Multithreading. But first... Overview of Multithreading in Java. Background on Threads

TCP Sockets. Multithreading. But first... Overview of Multithreading in Java. Background on Threads But first... Background on Threads Overview of Multithreading in Java Multithreading Java has build-in support for concurrent programming. This enables you to have multiple flows of control, represented

More information

Collections.sort(population); // Método de ordenamiento

Collections.sort(population); // Método de ordenamiento import java.util.collections; import java.util.linkedlist; import java.util.random; public class GeneticAlgorithms static long BEGIN; static final boolean _DEBUG = true; LinkedList population

More information

Java Memory Management

Java Memory Management Java Memory Management 1 Tracing program execution Trace: To follow the course or trail of. When you need to find and fix a bug or have to understand a tricky piece of code that your coworker wrote, you

More information

Generalization versus Abstraction

Generalization versus Abstraction Generalization versus Abstraction 1 Abstraction: simplify the description of something to those aspects that are relevant to the problem at hand. Generalization: find and exploit the common properties

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following represents the life-cycle of software development? (a) Analysis -> Design -> Coding -> Testing -> Operation and Maintenance

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

Stack Allocation. Run-Time Data Structures. Static Structures

Stack Allocation. Run-Time Data Structures. Static Structures Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

An Introduction To UML Class Diagrams Classes

An Introduction To UML Class Diagrams Classes An Introduction To UML Class Diagrams Classes 1. Represent a user-created or defined data type a. they are an abstract data type (ADT) b. they implement data hiding and encapsulation c. they establish

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

16 Collection Classes

16 Collection Classes 16 Collection Classes Collections are a key feature of the ROOT system. Many, if not most, of the applications you write will use collections. If you have used parameterized C++ collections or polymorphic

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

University of Central Florida. Engineering Data Structures EEL JAVA LABORATORY MANUAL (Revised edition, 2002) Maureen Murillo Avelino González

University of Central Florida. Engineering Data Structures EEL JAVA LABORATORY MANUAL (Revised edition, 2002) Maureen Murillo Avelino González University of Central Florida Engineering Data Structures EEL 4851 JAVA LABORATORY MANUAL (Revised edition, 2002) Maureen Murillo Avelino González - 2 - EEL 4851 Engineering Data Structures JAVA Laboratory

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

INSTRUCTIONS: Covers vol 1: chaps 9, 10, 14; vol 2: 1, 3; and the Mah Jong project

INSTRUCTIONS: Covers vol 1: chaps 9, 10, 14; vol 2: 1, 3; and the Mah Jong project Sample Final CS 3230 INSTRUCTIONS: Covers vol 1: chaps 9, 10, 14; vol 2: 1, 3; and the Mah Jong project 1. Consider the following fragments of code and choose the most accurate description. (Note that

More information

Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing. Integration and Object-Oriented Testing

Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing. Integration and Object-Oriented Testing Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt www.introsoftwaretesting.com Integration and Object-Oriented Testing Integration Testing Testing

More information

Introduction to Java A First Look

Introduction to Java A First Look Introduction to Java A First Look Java is a second or third generation object language Integrates many of best features Smalltalk C++ Like Smalltalk Everything is an object Interpreted or just in time

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

1.00 Lecture 17. Swing

1.00 Lecture 17. Swing 1.00 Lecture 17 Introduction to Swing Reading for next time: Big Java: sections 12.1-12.6 Swing Package of user interface classes for windows, menus, scroll bars, buttons, etc. Independent of hardware

More information

MODULE 4q - An abstract class

MODULE 4q - An abstract class MODULE 4q - An abstract class SQUARES AND CIRCLES The Block.java program incorporated a parent class Square and a child class Cube. The relationship was established by the declaration of class Cube which

More information

JAVA - OBJECT & CLASSES

JAVA - OBJECT & CLASSES JAVA - OBJECT & CLASSES http://www.tutorialspoint.com/java/java_object_classes.htm Copyright tutorialspoint.com Java is an Object-Oriented Language. As a language that has the Object Oriented feature,

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 1 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered include:

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004

Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004 Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004 INSTRUCTOR: I. E. LEONARD TIME: 3 HOURS Question 1. [10 = 5 + 5 pts] An operator is said to be overloaded when it is used

More information

Automatic generation of fully-executable code from the Domain tier of UML diagrams

Automatic generation of fully-executable code from the Domain tier of UML diagrams Abstract. Automatic generation of fully-executable code from the Domain tier of UML diagrams Macario Polo, Agustín Mayoral, Juan Ángel Gómez and Mario Piattini Alarcos Group - Department of Computer Science

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Bh Lecture Note 13 Event-driven programming The best practice in user-interface code development is the event-driven programming model in which code fragments can be associated with particular events

More information