Class attributes Chapter 3: Introduction to Classes and Objects.

Slides:



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

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
Information Hiding Chapter 5: Classes and Objects in Depth.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L13 (Chapter 21) Generics.
Introduction Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Objectives What are control structures Relational.
Chapter 2: Java Fundamentals Input and Output statements.
Introduction to methods Chapter 5: Classes and Objects in Depth.
Chapter 2: Java Fundamentals Java Program Structure.
Variables, Constants and Built-in Data Types Chapter 2: Java Fundamentals.
©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.
Objects and Instance attributes and variables Chapter 3: Introduction to Classes and Objects.
SE-1010 Dr. Mark L. Hornick 1 Defining Your Own Classes Part 3.
Chapter 10 METHODS AND CONSTRUCTORS 1. Accessing Objects  Referencing the object’s data: objectReference.data myCircle.radius  calling the object’s.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
Class and Object. Class vs Object Let us consider the following scenario… Class defines a set of attributes/fields and a set of methods/services. Object.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
1 Variables. 2 Receipt example What's bad about the following code? public class Receipt { public static void main(String[] args) { // Calculate total.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Objects and Classes Mostafa Abdallah
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Catie Welsh February 23,  Lab 4 due on Friday  Lab 5 will be assigned on Friday 2.
CS1201: Programming Language 2 Classes and objects.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Classes and Objects (contd.) Course Lecture Slides 19 May 2010.
Classes and Objects. Object Software objects are modeled after real-world objects in that they, too, have state and behavior. A software object maintains.
Introduction To Java Programming 1.0 Basic Concepts of Java Programming 2.0 Classes, Polymorphism and Inheritance 3.0 Exception handling 4.0.
Classes and Objects. How can one design a program?  Top-down structured design: uses algorithmic decomposition where each module denotes a major step.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Fundamentals 2 1. Programs and Data Most programs require the temporary storage of data. The data to be processed is stored in a temporary storage in.
COMP 110 More about classes Luv Kohli October 3, 2008 MWF 2-2:50 pm Sitterson 014.
Classes and Objects. Object vs. Class Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2  A class could be considered as a set of objects having.
OBJECT ORIENTED PROGRAMMING INTRODUCTION. WHAT IS OBJECT-ORIENTATION ALL ABOUT? Principles and techniques for system modeling which: Aim to produce a.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
Chapter 2 Clarifications
Examples of Classes & Objects
using System; namespace Demo01 { class Program
Object Oriented Programming
CS1201: Programming Language 2
Object-Oriented Programming Using C++
Dr Shahriar Bijani Winter 2017
Pass by Reference, const, readonly, struct
TO COMPLETE THE FOLLOWING:
Classes & Objects: Examples
Variables and Their scope
Chapter 1: Introduction
Code Animation Examples
Chapter 5: Classes and Objects in Depth
Classes and Objects.
Objects and Classes Creating Objects and Object Reference Variables
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
Chapter 5: Classes and Objects in Depth
Chapter 2: Java Fundamentals
CS1201: Programming Language 2
Chapter 5: Classes and Objects in Depth
Chapter 2: Java Fundamentals
Dr. R Z Khan Handout-3 Classes
CIS 110: Introduction to Computer Programming
PROGRAMMING ASSIGNMENT I
Previous Lecture: Today’s Lecture: Reading (JV):
Presentation transcript:

Class attributes Chapter 3: Introduction to Classes and Objects

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Class and Instance Attributes Instance attributes (and methods) are: associated with an instance (object) of the class. and accessed through an object of the class. each object of the class has its own distinct copy of instance attributes (and methods) Class attributes (and methods): live in the class can also be manipulated without creating an instance of the class. are shared by all objects of the class. do not belong to objects’ states.

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 3 Class Attributes and Objects A class attribute is in one fixed location in memory. Every object of the class shares class attributes with the other objects. Any object of the class can change the value of a class attribute. Class attributes (and methods) can also be manipulated without creating an instance of the class.

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 4 Class Attributes Declaration The class attributes (and methods) are declared as instance attribute but with the static modifier in addition. ; public static int studentNumber ; Modifiers Data Type Name

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 5 Class Attributes Access Class attributes (and methods) can also be manipulated without creating an instance of the class.. Course. studentNumber = 0 ; Class Name Attribute Name

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 6 class Course { // attributes public String studentName; public String courseCode ; public static int studentNumber; } public class CourseRegistration { public static void main(String[] args) { Course course1, course2; //Create and assign values to course1 course1 = new Course( ); Course.studentNumber = 1; course1.courseCode= new String(“CSC112“); course1.studentName= new String(“Majed AlKebir“); //Create and assign values to course2 course2 = new Course( ); Course.studentNumber ++; course2.courseCode= new String(“CSC107“); course2.studentName= new String(“Fahd AlAmri“); System.out.println(course1.studentName + " has the course “+ course1.courseCode + “ ” + course1.studentNumber); System.out.println(course2.studentName + " has the course “+ course2.courseCode + “ ” + course2.studentNumber); }