lecture09

lecture09 - 1.00 Introduction to Computation and Problem...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Class 9: Static Methods and Data Members 1.00 - Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward Announcements/Reminders The first quiz will be during class, 11:00 on Friday, October 7. The quiz is open book/open notes, but no electronic devices are allowed. We will schedule at least one review session during the week before the quiz. My own office hours this week are cancelled. 2 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Goals This the session in which we explain what static means. You will learn how to write classes with static methods and data members. 3 The UnitCircle Program public class UnitCircle { public static void main( String [] args ) { double circum = 2 * Math.PI; System.out.println( "Circumference of the unit circle = " + circum ); } } 4 2
Background image of page 2
Math.PI double circum = 2 * Math.PI; What is Math ? Class, object, or method? How do you know? Can you create Math instances? What is PI ? Class, data member, or method? It's defined as public static final double PI = 3.14159265358979323846; final makes it “read only” 5 Why Math.PI is static data member If PI is a data member, what object does it belong to? We can't create Math instances so it can't belong to an instance of the Math class. Because PI is declared static, it belongs to the Math class object . Access it using the class name, not an object reference. Yes, even classes are objects. How many Math class objects are there in any Java program? How many PI data members? 6 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
System.out.println() System.out.println( "Circumference= " + circum ); What is System ? Class, object or method? Can you create an instance of System ? What is
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 13

lecture09 - 1.00 Introduction to Computation and Problem...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online