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

Looking inside classes Fields, Constructors & Methods Week 3.
General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
ICE1341 Programming Languages Spring 2005 Lecture #18 Lecture #18 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
CLASSES & OBJECTS Representin’ real-world things in code-space Brian Camodeca, Mercyhurst College.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
Encapsulation CMSC 202. Types of Programmers Class programmers – Developers of new classes – Goal: Expose the minimum interface necessary to use a new.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Packages.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
CET203 SOFTWARE DEVELOPMENT Session 1A Revision of Classes.
10-Nov-15 Java Object Oriented Programming What is it?
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Visibility Control.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
CourseOutline Example & JavaBeans Lec Start with Example Displaying Course Outlines User will select either course “web design & development” or.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
More on Objects Mehdi Einali Advanced Programming in Java 1.
Peyman Dodangeh Sharif University of Technology Spring 2014.
Classes and Objects - Part I. What is an Object? An Object has two primary components: state – properties of the object behavior – operations the object.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
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.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Comp1004: Building Better Objects II Encapsulation and Constructors.
COMP Information Hiding and Encapsulation Yi Hong June 03, 2015.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
More Sophisticated Behavior
Module Road Map Refactoring Why Refactoring? Examples
Phil Tayco Slide version 1.0 Created Sep 18, 2017
Abstraction, Interface, Inheritance, Polymorphism, Override / Overload
University of Central Florida COP 3330 Object Oriented Programming
Object-Oriented Programming
Interfaces.
University of Central Florida COP 3330 Object Oriented Programming
Creating Your OwnClasses
What is Encapsulation, Benefits, Implementation in Java
Anatomy of a class Part I
ATS Application Programming: Java Programming
Advanced Programming in Java
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Advanced Programming in Java
Encapsulation & Abstraction
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Defining Your Own Classes Part 1
COMP 110 Information hiding and encapsulation
Chapter 4: Writing classes
Overview of Eclipse Lectures
Classes and Objects housefly object Insect class mosquito object
Encapsulation and Constructors
Learning Objectives Classes Constructors Principles of OOP
Private.
The Object-Oriented Thought Process Chapter 04
Announcements Program 2 is due tomorrow by noon Lab 4 was due today
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Week 5 Review & Announcement
Object-Oriented Programming
By Rajanikanth B OOP Concepts By Rajanikanth B
Chapter 11 Inheritance and Polymorphism Part 1
Classes and Objects CGS3416 Spring 2019.
ITE “A” GROUP 2 ENCAPSULATION.
Anatomy of a class Part I
CSG2H3 Object Oriented Programming
Chapter 5 Classes.
Presentation transcript:

Encapsulation

Encapsulation Encapsulation is in used in JAVA to hide the implementations details from user. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class. However if we setup public getter and setter methods to update and read the private data fields then the outside class can access those private data fields via public methods. www.prolearninghub.com

Encapsulation This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is known as data hiding www.prolearninghub.com

Encapsulation Example Here is a sample code to demonstrate Encapsulation in java, Fruit class has all related data like name, taste, color.. etc and behavior like calculateCost in a single unit. www.prolearninghub.com

Encapsulation Example package com.beingjavaguys.core;    public class Fruit {    private String name;    private String price;    private String taste;    private Fruit(String name, String price, String taste) {     this.name = name;     this.price = price;     this.taste = taste;    }   www.prolearninghub.com

Encapsulation Example public void calculateCost() { }     }      public String getName() {     return name;    }    public void setName(String name) {     this.name = name;    public String getPrice() {     return price;    public void setPrice(String price) {     this.price = price;     www.prolearninghub.com