CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
UML Class Diagram: class Rectangle
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Advanced Inheritance Concepts. In this chapter, we will cover: Creating and using abstract classes Using dynamic method binding Creating arrays of subclass.
COP 3003 Object-Oriented Programming - Polymorphism Dr. Janusz Zalewski, Fall 2013 Prepared by Dr Dahai Guo.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
1 Abstract Class There are some situations in which it is useful to define base classes that are never instantiated. Such classes are called abstract classes.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Inheritance in the Java programming language J. W. Rider.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Classes, Interfaces and Packages
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary.
Java Programming, Second Edition
Java Inheritance.
Inheritance.
Advanced Inheritance Concepts
Chapter 14 Abstract Classes and Interfaces
Inheritance and Polymorphism
Chapter 11 Inheritance and Polymorphism Part 1
Final and Abstract Classes
Chapter 11 Inheritance and Encapsulation and Polymorphism
Presentation transcript:

CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the methods that manipulate it into a single object. In particular, it refers to the ability of an object to hide particular data and methods from other objects, exposing them only through specified methods that are marked with the “public” keyword. Define/Explain inheritance. In object-oriented programming, inheritance is where a class automatically can be made to have characteristics of another class. That is, a sub-class will inherit variables and methods from a super-class that is indicated using the “extends” keyword. Objects of a particular sub-class can be treated as members of a common super-class Define/Explain polymorphism. In object-oriented programming, polymorphism is the ability of different objects to respond to the same message, each in a different way. Polymorphism occurs when we are referring to the sub-class as a member of its super-class. If there is a method or variable in the sub-class which overrides a method or variable in its super-class, then the method or variable of the sub-class is used.

CS 5JA Introduction to Java Pop quiz pt. 2 Give an example of where we would use the “this” keyword. The “this” keyword lets an object refer to itself. It is often be used when calling invoking a method where we want to pass in the entire object as an argument. It is also used to specify the global instance variable when a there is another local variable with the same name. This regularly happens in constructors when we want to set the instance variable to the local variable that gets passed in as an argument: int num; public MyClass(int num) { this.num = num; }

CS 5JA Introduction to Java Pop quiz pt. 3 When is the “abstract” keyword used? The abstract keyword is used when we want to force particular variables to be defined or methods to be implemented in a sub-class. When a class has abstract variables or methods, then the class itself must be abstract– which means that it can not be instantiated. However, any sub-classes that extend the abstract super-class will automatically inherit all the non-abstract variables and methods. Additionally, they will be required to implement the abstract variables and methods.

CS 5JA Introduction to Java Pop quiz pt. 3 abstract class MySuperClass //cannot be instantiated { public abstract int num1; int num2 = 373; public abstract void printNums(); public void printNum2() {System.out.println(“num2 = “ + num2); } public class MySubClass1 extends MySuperClass //must implement abstract stuff from the super-class { int num1 = 7; //implenents abstract variable public void printNums() //implements abstract method { //can refer to super-class’s variables as well. System.out.println(“num1 = “ + num1 + “ num2 = “ + num2); //can refer to super-class’s methods as well. printNum2(); }

CS 5JA Introduction to Java Pop Quiz pt 4 What does the “has-a” relationship between objects signify? An object may be composed in part out of other objects. For example, a bicycle object “has a” crank, a chain, a handle-bar, a frame, a seat, gears, etc. What does the “is-a” relationship between objects signify? An object often “is-a” type of object as well. For example, you might want to specify that a Triangle is a type of TwoDimensionalShape. This relationship is defined with inheritance using the “extends” keyword

CS 5JA Introduction to Java Pop Quiz pt 5 What does the “static” keyword refer to? If a variable or method in a class is defined as static, then it means that the variable or method will be the same for all instantiations of objects of that class. Moreover, the method or variable exists and can be used even if no objects are instantiated at all. A static method can not refer to object instance variables or methods (ie, non-static methods or variables). However, a non-static method can refer to static methods and variables. What does the “final” keyword refer to? A final variable is a non-variable variable– also known as a “constant”. Once a final variable is created in cannot be changed.

CS 5JA Introduction to Java On the test Questions that make sure you understand the definitions of common terms & concepts: object, class, inheritance, polymorphism, array, List, constructor, etc. Questions that make sure you understand basic syntax: looping through an multi-dimensional array, using a switch statement, looping through a List and doing actions based on the value in the List, order of operations, method signatures, scope of variables, etc Questions that show you know how to think about organizing your code into different classes and methods, how to model a problem. Questions that make sure you can debug obvious errors. Maybe some tougher extra-credit problems. The test will take 1 hour.