A note about coverage Say you have an if statement:

Slides:



Advertisements
Similar presentations
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 14: More About Classes.
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
9-1 Chapter.8 Classes & Objects: A deeper look –Static Class Members –Passing & Returning Objects from Methods –The toString method –Writing an equals.
Chapter 8: A Second Look at Classes and Objects
© 2010 Pearson Addison-Wesley. All rights reserved. 9-1 Chapter Topics Chapter 9 discusses the following main topics: –Static Class Members –Passing Objects.
Reinforced Concrete: A Fundamental Approach, Sixth Edition By Edward G. Nawy Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey.
Access to Names Namespaces, Scopes, Access privileges.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Static Class Members Wrapper Classes Autoboxing Unboxing.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 6: A First Look at Classes
Copyright © 2003 by Pearson Education, Inc., publishing as Prentice Hall, Upper Saddle River, NJ. All rights reserved. To view maps beyond the range 59-76,
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Java Classes Appendix C © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
Chapter 4: Loops and Files
9-2  Static Class Members  Passing Objects as Arguments to Methods  Returning Objects from Methods  The toString method  Writing an equals Method.
I NTRODUCTION TO PROGRAMMING Starting Out with Java: From Control Structures through Objects CS 146 Class Notes: Cooper & Ji & Varol Fall 09.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 5, Methods Java How to Program, Late Objects Version, 10/e
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William.
Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter 5: Methods.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo CET 3640 © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 9: A Second Look at Classes and Objects
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
Figure Materials in Basal Reading Programs Gail E. Tompkins Literacy for the 21st Century, 3e Copyright ©2003 by Pearson Education, Inc. Upper Saddle.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Creating Classes from Other Classes Appendix D © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Figure A--1 Thomas L. Floyd Digital Fundamentals, 8e Copyright ©2003 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
Object-Oriented Design Chapter 7 1. Objectives You will be able to Use the this reference in a Java program. Use the static modifier for member variables.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
A Second Look at Classes and Objects - 1 Static Class Members
Methods Chapter 6.
Operator Overloading; Class string
Chapter 3 Inheritance © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
©2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
CMSC 202 Static Methods.
Chapter 9: A Second Look at Classes and Objects
Chapter 9: A Second Look at Classes and Objects
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 6 Methods: A Deeper Look
Figure 11.2 Evaluation of Illustrations
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
Extra Nomenclature Practice Answers
Chapter 3 Introduction to Classes, Objects Methods and Strings
Figure 11.2 Evaluation of Illustrations
Section 10.5 The Dot Product
(C) 2010 Pearson Education, Inc. All rights reserved.
Unit 4 Review Answers.
Presentation transcript:

A note about coverage Say you have an if statement: if (sunShining && temp > 75) You need 4 tests. sunShining T/F and temp > 75 and temp <= 75. If you can’t make 4 tests, you probably have something ahead that is making one of the conditions obsolete.

Quiz today Two parts White paper – your individual answer – put these in the folder when done. Make sure name is on. Green paper – group responses – start only when ALL of the individual papers are submitted. Grades based on 40% individual effort and 60% group. 30 minutes total.

Static Class Members Static fields and static methods do not belong to a single instance of a class. To invoke a static method or use a static field, the class name, rather than the instance name, is used. Example: double val = Math.sqrt(25.0); Class name Static method

Static Fields Class fields are declared using the static keyword between the access specifier and the field type. private static int instanceCount = 0; The field is initialized to 0 only once, regardless of the number of times the class is instantiated. Primitive static fields are initialized to 0 if no initialization is performed. Examples: Countable.java, StaticDemo.java

Static Fields instanceCount field (static) 3 Object1 Object3 Object2

Static Methods Methods can also be declared static by placing the static keyword between the access modifier and the return type of the method. public static double milesToKilometers(double miles) {…} When a class contains a static method, it is not necessary to create an instance of the class in order to use the method. double kilosPerMile = Metric.milesToKilometers(1.0); Examples: Metric.java, MetricDemo.java

Static Methods Static methods are convenient because they may be called at the class level. They are typically used to create utility classes, such as the Math class in the Java Standard Library. Static methods may not communicate with instance fields, only static fields.