CSE 115AnnouncementsLesson PlanClass DefinitionsClass NamesClass BodyAnswer: In file Date.javaSlide 8Constructor DefinitionSlide 10September 19, 2008AnnouncementsLesson PlanClass definitions (syntax)Class DefinitionsClass Headerpublic class identifierpublic (keyword) access control modifier stating that everything within the program has accessclass (keyword) states that we are about to define a classidentifier (name) Name of the class we are definingClass BodyClass Names Style – First letter of a class name is upper case followed by lower case letters until the end of the first word, subsequent words have their first letter in upper case. (camel case)Eg) MyFirstClassNameThe name of the class tells us the name of the fileClass BodySurrounded by { }Inside the {} are the definitions of the class’ properties followed by the definitions of the class’ capabilities.Exercise: Write the code for a class named Date that is in a package named calendar.Answer: In file Date.javapackage calendar;public class Date {}new Date();We are also calling a special capability of the object called a constructor. A constructor sets up the initial state of the object.State: The set of all the properties of an object and their values at a given time.Constructor DefinitionConstructor Headerpublic identifier()public – means same as beforeidentifier – same as the name of the classConstructor BodySurrounded by { }Answer: In file Date.javapackage calendar;public class Date { public Date() {
View Full Document