














































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































Anasse Bari, Ph.D. Courant Institute of Mathematical Sciences Department of Computer Science CS101 Introduction to Computer Science
❖ Introducing the concepts of Encapsulation and Inheritance ❖ Learning the Super keyword, superclass methods and data fields ❖ Introducing the concept of polymorphism ❖ Learning how to use interfaces and abstract classes in Java ❖ Introducing the comparable java interface ❖ Introducing casting and instance of ❖ Understanding where to use an interface or an abstract class 2
❖ Object-oriented Design: A problem-solving methodology that produces a solution to a problem in terms of self-contained entities called objects ❖ Object: A thing or entity that makes sense within the context of the problem ❖Class: A class is a blueprint or template or set of instructions to build a specific type of object. Every object is built from a class. 4
❖Encapsulation means that all data members (fields) of a class are declared private. Some methods may be private, too. ❖The class interacts with other classes (called the clients of this class) only through the class’s constructors and public methods. ❖Constructors and public methods of a class serve as the interface to class’s clients. ❖Hides the fine detail of the inner workings of the class ❖The implementation is hidden ❖Often called "information hiding" ❖Part of the class is visible ❖The necessary controls for the class are left visible ❖The class interface is made visible ❖The programmer is given only enough information to use the class 5
❖ Changes in the code create software maintenance problems ❖ Usually, the structure of a class (as defined by its fields) changes more often than the class’s constructors and methods 7
❖Inheritance allows a software developer to derive a new class from an existing one ❖The existing class is called the parent class, or superclass, or base class ❖The derived class is called the child class or subclass ❖As the name implies, the child inherits characteristics of the parent That is, the child class inherits the methods and data defined by the parent class ❖A class can extend another class, inheriting all its data members and methods while redefining some of them and/or adding its own. ❖Inheritance represents the is a relationship between data types 8
Class Goalkeeper extends SoccerPlayer {......} …
Inheritance: Super keyword
Inheritance: Super keyword
Inheritance: Superclass Example 1 public class C1{ protected int x; public void setX (int x) { this.x = x; } //the rest of the class definition } public class C2 extends C1{ protected float c; public C2 (float c, int x) { this.c = c; setX(x); } //the rest of the class definition }
Inheritance: Superclass Example 1 (cont’d)