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)

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
Passing information through Parameters ( our setter methods or mutators) Formal Parameter – parameter in the method. public void SetA(int x){ (int x) is.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Objects. Strings String x = “abc”; String is a class, not a primitive x.charAt(2) is ‘b’ use name and ‘.’ and name.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Lecture 5: Objects and Classes, cont’d Continue with the Player example Introduce GOAL as a final static variable that applies to all objects of the class.
Understanding class definitions Looking inside classes.
OOPDA Review. Terminology class-A template defining state and behavior class-A template defining state and behavior object-An instance of a class object-An.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Constructors A constructor is a method that creates an object in Java. It does not return anything and it is not void. It’s only purpose is to create an.
Lecture 3. 2 Introduction Java is a true OO language -the underlying structure of all Java programs is classes. Everything must be encapsulated in a class.
UML Basics & Access Modifier
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Creating Simple Classes. Outline of Class Account Class Account Account # Balance Holder name phone# Overdrawn (true/false) Data Members Open Credit Debit.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Composition - 1 J. Sant.. Agenda Define Composition Reuse and Composition. Composition in Java. Composition Exercise with simple containment.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
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.
10-Nov-15 Java Object Oriented Programming What is it?
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Understanding class definitions
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
CourseOutline Example & JavaBeans Lec Start with Example Displaying Course Outlines User will select either course “web design & development” or.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
JAVA PROGRAMMING PART III. METHOD STATEMENT Form of method statement [ ] [static] ( [ ]) { } Example public static void main(String args[])
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Classes and Objects - Part I. What is an Object? An Object has two primary components: state – properties of the object behavior – operations the object.
Introduction To Java Programming 1.0 Basic Concepts of Java Programming 2.0 Classes, Polymorphism and Inheritance 3.0 Exception handling 4.0.
Methods.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Class Fundamentals BCIS 3680 Enterprise Programming.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Re-Intro to Object Oriented Programming
Class Structure 15-Jun-18.
Creating Your OwnClasses
Anatomy of a class Part I
Classes In C#.
CLASS DEFINITION (> 1 CONSTRUCTOR)
Java Programming with BlueJ
Understanding class definitions
Class Structure 16-Nov-18.
An Introduction to Java – Part II
Creating Objects in a Few Simple Steps
Classes & Objects: Examples
Class Structure 7-Dec-18.
Implementing Classes Chapter 3.
The Object-Oriented Thought Process Chapter 04
Class Structure 2-Jan-19.
Understanding class definitions
Class Structure 25-Feb-19.
JAVA CLASSES.
Object-Oriented Programming
Instance Method – CSC142 Computer Science II
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Encapsulation.
Anatomy of a class Part I
Day 11 The Last Week!.
Presentation transcript:

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) Constructor (method that creates the object) Methods ( get and set the instance variables and other actions as necessary)

Instance Variables Properties of the object. What it knows about itself. Created in a field so also called field data private String color; private int legs; private String name; I know my color, how many legs I have and my name.

CONSTRUCTOR public className() { Assign instance variables here } public Bug() { String color = “red”; int legs = 6; String name = “Beetle”; }

Parameter ( ) Supplies extra information to a method that it needs to execute. Required for constructors & all methods. public Bug() { public static void main(String[]args) { public void setName(“String name”);

Classes create objects from the constructor with the word new public Bug() { String color = “red”; int legs = 6; String name = “Beetle”; } Bug b = new Bug(); public Bug(String c, int l, String n) { color = c; legs = l; name = n; } Bug b = new Bug(“Red”, 6, “Beetle”); (String, int, String)

Methods Accessor Methods: Access information from our instance variables. Instance variable: name name is a String public String getname() { return name; }

Mutator Methods Change information in our instance variables. Called setters. Instance Variable name public void setName(String n); name = n; } Doesn’t return anything so it is void.

Objects call their method with dot operator. Bug b = new Bug(); // b is the object public void setName(String n); // is the method b.setName(“Harry”); System.out.println(b.getname()); prints Harry