Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create.

Slides:



Advertisements
Similar presentations
JAVA Revision Lecture Electronic Voting System Marina De Vos.
Advertisements

Understanding class definitions Looking inside classes 5.0.
Looking inside classes Fields, Constructors & Methods Week 3.
Fields, Constructors, Methods
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Road Map Introduction to object oriented programming. Classes
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
Lecture 10: Inheritance Subclasses and superclasses The inheritance chain Access control The Object cosmic superclass The super keyword Overriding methods.
Understanding class definitions Looking inside classes 3.0.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
Understanding class definitions Looking inside classes.
Abstract Classes and Interfaces
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Object Oriented Design: Identifying Objects
CPSC150 Spring 2007 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Understanding class definitions
1 COS 260 DAY 3 Tony Gauvin. 2 Agenda Questions? 1 st Mini quiz on chap1 terms and concepts –Today In BlackBoard –30 min., M/C and short answer, open.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Arithmetic, Class Variables and Class Methods Week 11
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Looking inside classes Conditional Statements Week 4.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
Object-Oriented Programming in Java. 2 CS2336: Object-Oriented Programming in Java Buzzwords interfacejavadoc encapsulation coupling cohesion polymorphic.
Understanding class definitions Exploring source code 6.0.
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.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
1 CSC 221: Computer Programming I Fall 2005 graphics & design  Dot & DotRace revisited  Circle class implementation  adding Circle methods  static.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Chapter 4 - Finishing the Crab Game
Re-Intro to Object Oriented Programming
Chapter 15 Abstract Classes and Interfaces
Java Primer 1: Types, Classes and Operators
Lecture 10: Inheritance Subclasses and superclasses
Objects First with Java
Understanding class definitions
Introduction to Classes and Objects
Understanding class definitions
An Introduction to Java – Part II
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Encapsulation and Constructors
Announcements & Review
CS2011 Introduction to Programming I Objects and Classes
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)
Understanding class definitions
Applying OO Concepts Using Java
Which best describes the relationship between classes and objects?
Chapter 14 Abstract Classes and Interfaces
Announcements & Review
Chapter 13 Abstract Classes and Interfaces Part 01
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Topics to cover Instance variables vs. local variables.
Day 11 The Last Week!.
Presentation transcript:

Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create an object or vice versa? –Two important parts of classes we discussed on M ? –Fields have data types associated with them e.g: –Parameters vs. Return values (Optional?) –What are keywords? –Signature

Basic Elements A class has three basic elements: public class ClassName { Fields Constructors Methods }

Classes have a wrapper around them. An example for the Circle Class public class Circle { Inner part of the class omitted } The outer wrappings of different classes look pretty much the same, Only the name changes to match the class

The inner workings The inner part of the class deals with the code for fields, constructors and methods It is the fields, constructors and methods that give a class its uniqueness

Different parts of a class: Fields Fields store values for an object. They are also known as instance variables. Use the Inspect option in BlueJ to view an object’s fields. public class Circle { private int diameter ; private int xPosition ; private int yPosition ; private String color ; private boolean isVisible ; }

Field Signature public int diameter; data type field namevisibility modifier Ends with a semicolon What happens if you omit a semicolon?