CSC153, Class 32: Object, Classes, and Methods Overview: * What is a class? * A problem: Describing fractions. + Fields. + Methods. + Constructors. * Different kinds of classes * Design decisions Notes: * Exam 2 due. It sounds like this was an infamous Rebelsky exam. * Read J4 over break (if at all possible). * Today's class: Lecture/recitation. * Have a great break! ---------------------------------------- What is a class? * A gathering of students and faculty to learn. How about in the CS sense? * A collection of objects ... * A description for creating similar objects. * A template or "Platonic ideal" for objects. In Java, typically three aspects to a class * Fields * Methods * Constructors A field is something that you put data into Fields tell you the kinds of attributes an object has. A constructor gives instructions for building a new object Constructors tell you how to fill in those attributes A method is simply a function. It often performs its work based on the fields of the object. Let's look at how you might do this in actual Java. in that class. ---------------------------------------- Four levels of protection. From most restrictive to least private Only objects in the same class can access. package Adds ability of other objects in the same "package" protected Adds ability of subclasses public Anything goes When you want package protection, you don't explicitly give a protection level. Nothing = "package".