Download presentation
Presentation is loading. Please wait.
Published byShanna Edwards Modified over 8 years ago
1
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
2
Basic Elements A class has three basic elements: public class ClassName { Fields Constructors Methods }
3
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
4
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
5
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 ; }
6
Field Signature public int diameter; data type field namevisibility modifier Ends with a semicolon What happens if you omit a semicolon?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.