Object Oriented Programming

Slides:



Advertisements
Similar presentations
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Advertisements

Final and Abstract Classes
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
Chapter 10 Classes Continued
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Java Implementation: Part 3 Software Construction Lecture 8.
Class Inheritance UNC-CHAPEL HILL COMP 401 BRIAN CRISTANTE 5 FEBRUARY 2015.
JAVA BASICS Prepared by The Smartpath Information Systems
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.
Inheritance The Basics in Java. Definition  A class that is derived from another class is called a subclass (also a derived class, extended class, or.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Visibility Control.
C# G 1 CSC 298 Object Oriented Programming Part 2.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
CITA 342 Section 1 Object Oriented Programming (OOP)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Introduction to Object-oriented Programming
Inheritance.
Abstract classes and interfaces
OOP: Encapsulation &Abstraction
Software Construction
Objects as a programming concept
University of Central Florida COP 3330 Object Oriented Programming
Haidong Xue Summer 2011, at GSU
Inheritance and Polymorphism
Table of Contents Class Objects.
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
CSC 205 Java Programming II
CS240: Advanced Programming Concepts
CSC 143 Inheritance.
Encapsulation.
Abstract classes and interfaces
Chapter 9 Object-Oriented Programming: Inheritance
Week 6 Object-Oriented Programming (2): Polymorphism
Interfaces.
Advanced Java Programming
Java Inheritance.
Welcome back to Software Development!
Tonga Institute of Higher Education
Fundaments of Game Design
Chapter 14 Abstract Classes and Interfaces
By Rajanikanth B OOP Concepts By Rajanikanth B
Abstract classes and interfaces
Java Programming Language
Final and Abstract Classes
Unit-2 Objects and Classes
Visibilities and Static-ness
Chapter 11 Inheritance and Encapsulation and Polymorphism
CSG2H3 Object Oriented Programming
Presentation transcript:

Object Oriented Programming www.hndit.com Object Oriented Programming Access Modifiers Lecture 10

Access modifiers: Public Protected Private www.hndit.com Access modifiers: Public Protected Private there are four access controls (levels of access) but only three access modifiers. The fourth access control level (called default or package access) is what you get when you don’t use any of the three

www.hndit.com every class, method, and instance variable you declare has an access control, whether you explicitly type one or not. Although all four access controls (which means all three modifiers) work for most method and variable declarations, a class can be declared with only public or default access; the other two access control levels don’t make sense for a class

www.hndit.com CLASS ACCESS

Default Access www.hndit.com A class with default access has no modifier preceding it in the declaration. In other words, it’s the access control you get when you don’t type a modifier in the class declaration. Think of default access as package-level access, because a class with default access can be seen only by classes within the same package. For example, if class A and class B are in different packages, and class A has default access, class B won’t be able to create an instance of class A, or even declare a variable or return type of class A.

Public Access www.hndit.com A class declaration with the public keyword gives all classes from all packages access to the public class. In other words, all classes in the Java Universe (JU) have access to a public class.

Other (Nonaccess) Class Modifiers www.hndit.com Other (Nonaccess) Class Modifiers

Final Classes www.hndit.com When used in a class declaration, the final keyword means the class can’t be subclassed. In other words, no other class can ever extend (inherit from) a final class, and any attempts to do so will give you a compiler error.

Method and Variable Declarations and Modifiers www.hndit.com Method and Variable Declarations and Modifiers

Member Access www.hndit.com Whereas a class can use just two of the four access control levels (default or public), members can use all four: ■ public ■ protected ■ default ■ private

Public Members www.hndit.com When a method or variable member is declared public, it means all other classes, regardless of the package they belong to, can access the member

Private Members www.hndit.com Members marked private can’t be accessed by code in any class other than the class in which the private member was declared.

Protected and Default Members www.hndit.com The protected and default access control levels are almost identical, but with one critical difference. A default member maybe accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed (through inheritance) by a subclass even if the subclass is in a different package.

www.hndit.com