Sadegh Aliakbary Sharif University of Technology Fall 2010.

Slides:



Advertisements
Similar presentations
Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Advertisements

INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Programming Languages and Paradigms Object-Oriented Programming.
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
Object Oriented Programming: Java Edition By: Samuel Robinson.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
More about Class 靜宜大學資工系 蔡奇偉副教授 ©2011. 大綱 Instance Class Members Class members can be associated with an instance of the class or with the class as a.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
Programming in Java CSCI-2220 Object Oriented Programming.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Session 7 Methods Strings Constructors this Inheritance.
Objects and Classes Mostafa Abdallah
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.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
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:
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Objects and Classes.
CSI 3125, Preliminaries, page 1 Compiling the Program.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
More on Objects Mehdi Einali Advanced Programming in Java 1.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Peyman Dodangeh Sharif University of Technology Spring 2014.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Classes - Intermediate
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.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Object Initialization and Clean up Mehdi Einali Advanced Programming in Java 1.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Object Initialization and Clean up
Advanced Programming in Java
Advanced Programming in Java
Advanced Programming Behnam Hatami Fall 2017.
Chapter 14 Abstract Classes and Interfaces
Corresponds with Chapter 5
Advanced Programming in Java
Presentation transcript:

Sadegh Aliakbary Sharif University of Technology Fall 2010

Agenda Review of last chapter Access specifiers Static fields and methods Initialization Cleanup Fall 2010Sharif University of Technology2

Review (Arrays) Fall 2010Sharif University of Technology3

Review(1) Fall 2010Sharif University of Technology4

Review(2) Fall 2010Sharif University of Technology5

Review(3) There is three type of variable in this code array reference array[i] references array[i] objects Fall 2010Sharif University of Technology6

Object Scopes Fall 2010Sharif University of Technology7

Access Specifiers public Interface access private Don’t touch! Fall 2010Sharif University of Technology8

Example Fall 2010Sharif University of Technology9

Public classes You can declare a class which is not public The class is visible within the file There can be only one public class per file The name of the public class must exactly match the name of the file including capitalization It is possible to have a java file with no public class Is not typical Fall 2010Sharif University of Technology10

Static properties static properties are shared among all the objects static properties are properties of classes Not objects What is the application? Integer.MAX_VALUE Player.NumberOfObjects Fall 2010Sharif University of Technology11

Static methods Static methods can access only static properties Static methods are actually class operations Not object operations If a method uses only static fields, make it static! Static methods are accessible via classes double d = Double.parseDouble("12"); String s = String.valueOf(12); public static void main(String[] args) Fall 2010Sharif University of Technology12

Constructors Constructor is a special method With same name as the class Without any return type is called when an object is instantiated May have parameters Default constructor : no parameter Is implicitly implemented You can write your own constructor If you write any constructor, default implicit constructor is vanished. Fall 2010Sharif University of Technology13

Constructor example Fall 2010Sharif University of Technology14

Fall 2010Sharif University of Technology15

Fall 2010Sharif University of Technology16

Method Overloading Methods with the same name in the same class With different parameters Fall 2010Sharif University of Technology17

Fall 2010Sharif University of Technology18

Return type method overloading Why this is not permitted? Fall 2010Sharif University of Technology19

Method-property access How does getArea() know where radius is? Fall 2010Sharif University of Technology20

Compiler solution A reference to the object is implicitly passed to methods circle.getArea() is converted something like: Circle.getArea(circle) What if you want to access this circle object? Use this keyword this is available within non-static methods Fall 2010Sharif University of Technology21

Sample Fall 2010Sharif University of Technology22

Static again What are static methods? Methods without implicit this Static methods are bound to classes, not objects Fall 2010Sharif University of Technology23

Finalize method Java has no delete Java has no destructor Java has a special method: finalize finilize() is called when the object is garbage- collected Why we may need finalize? Garbage collection is only about memory Fall 2010Sharif University of Technology24

Quiz! Write a java class for representing … Fall 2010Sharif University of Technology25

Fall 2010Sharif University of Technology26

Fall 2010Sharif University of Technology27