ITE “A” GROUP 2 ENCAPSULATION.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
PACKAGES. PACKAGES IN JAVA A package is a collection of related classes and interfaces in Java Packages help in logical grouping of classes and interfaces.
Nested Classes Yoshi Modified from:
Road Map Introduction to object oriented programming. Classes
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Introduction to methods Chapter 5: Classes and Objects in Depth.
Inheritance #1 First questions Similar to Python? What about visibility and encapsulation? – can an object of the child class access private members.
1 Pertemuan 6 Object Oriented Programming Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Object Oriented Software Development
Writing Classes (Chapter 4)
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
Chapter 10 METHODS AND CONSTRUCTORS 1. Accessing Objects  Referencing the object’s data: objectReference.data myCircle.radius  calling the object’s.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
CS170 ygao JAVA, C4Slide 1. CS170 ygao JAVA, C4Slide 2.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Introduction To Objects Oriented Programming Instructor: Mohammed Faisal.
Classes - Intermediate
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
Topics Instance variables, set and get methods Encapsulation
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Comp1004: Building Better Objects II Encapsulation and Constructors.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
University of Central Florida COP 3330 Object Oriented Programming
Examples of Classes & Objects
University of Central Florida COP 3330 Object Oriented Programming
Creating Your OwnClasses
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Defining Classes and Methods
Classes & Objects: Examples
Encapsulation and Constructors
Group Status Project Status.
Classes and Objects.
Defining Classes and Methods
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 9 Objects and Classes
Dr. R Z Khan Handout-3 Classes
Classes and Objects CGS3416 Spring 2019.
Chapter 11 Inheritance and Encapsulation and Polymorphism
Encapsulation.
Chapter 7 Objects and Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

ITE “A” GROUP 2 ENCAPSULATION

What is encapsulation The binding or wrapping of data and codes into a single entity Thus the data gets hidden from being accessed directly from outside the class. All the members of a class are private by default, thus preventing them from being accessed from outside the class. This is similar to a capsule where several medicines are kept inside the capsule thus hiding them from being contaminated or directly consumed from outside.

Real life example of Encapsulation

Benefits and reasons of encapsulation Encapsulation is also useful in hiding the data or variables of a class from an illegal direct access. It provides your code - security, flexibility and its easy maintainability through encapsulation. NOTE: To achieve encapsulation in java, declare the variables of a class as private and provide public setter and getter methods to modify and view the variables values

Keywords in Encapsulation Class is a collection of object of the same kind and its also called an entity A method is a block of statements that has a name, performs the task of a class and can be executed by calling (also called invoking) it from some other place in your program. Object is used to reference a class. It is what actually runs in the program and can be a method, variable, data variable etc Setter is used to pass a variable or update the instance of a variable. Getter is used to print, retrieve or read value of a variable .

CODE package encapsulation.java; class A{ private int i; public void setI( int j) { i = j*j; } public int getI( ) { return i; } } public class EncapsulationJava { public static void main(String[] args) { A obj = new A(); obj.setI(5); int d=obj.getI(); System.out.println("Hey! she is "+d+"yrs now"); }