SlideShare a Scribd company logo
A class contains two basic elements, state and behavior. With this being said a class
must contain some sort of constructor for these two elements. On top of this there are
class definition statements and object constructors for the objects that a class contains.
Also a class can become a subclass of another class, and this is done in the constructor
for the class itself. I will include a quick snippet of code that shows the different
members of a class definition then explain them.

//subclass declaration of MyClass from MySuperClass using the MyInterface interface
public class MyClass extends MySuperClass implements MyInterface
{                          //body of class includes fields (states), methods (behavior),
and object declaration
     public int myClassState1, myClassState2; //field declarations available to all
classes
     private int myClassState3, myClassState4; //field declarations available to this
class only

    public MyClass (int state1, int state2, int state3, int state4) {   //object constructor
          myClassState1 = state1;
          myClassState2 = state2;
          myClassState3 = state3;
          myClassState4 = state4;
     }

   public void setState1 (int newValue) {            //method used to update
myClassState1
        myClassState1 = newValue;
   }

    public int getState1 () {  //method used to return the value of myClassState1
         return myClassState1;
    }
}

In the beginning of this code snippet there is a class declaration that declares the class
as a sub class of MySuperClass and uses the MyInterface interface. This is the general
form of a class declaration, remembering that because the MyClass is a subclass of
MySuperClass, MyClass inherits the elements of MySuperClass.

Next are the variables that define the state of the class. These variables are the
myClassState1...2...3....4. These are the variables that are used to modify the contents
of the objects of that class. Two of these variable state are private meaning that the only
objects or classes that can use them are the MyClass.

The next lines declare the object of the class that uses all four of the variables. These
variable now become part of the object of the class and the object is then used to
modify these state variables using the methods of the class.

Next are the two methods, one is the setState1 which sets the state of the
myClassState1 of the objects of the class. The other method is the getState1 which
returns the value of the state of the variable myClassState1 of the object MyClass.

I am not 100% but to use the objects and methods later on in the program you need to
first declare an object of the class similar to this:

MyClass classObjectName = new MyClass(1, 2, 3, 4);

Then to use this object's methods it is done similar to this:

stateHandlerVariable = classObjectName.getState1();

More Related Content

Viewers also liked

Dignitas the real facts
Dignitas   the real factsDignitas   the real facts
Dignitas the real facts
AJRMBR
 
Papeleria
PapeleriaPapeleria
Papeleriaperisp
 
Week1 dq5
Week1 dq5Week1 dq5
Week1 dq5
amaxwell2012
 
Dr APJ Award certificate 001
Dr APJ Award certificate 001Dr APJ Award certificate 001
Dr APJ Award certificate 001Arish D
 
Ficha nona
Ficha nonaFicha nona
Ficha nonaPreview
 
Wearform
WearformWearform
Wearform
steve121smith
 
Sports videography reel
Sports videography reelSports videography reel
Sports videography reelrenniecowan2
 

Viewers also liked (12)

Dignitas the real facts
Dignitas   the real factsDignitas   the real facts
Dignitas the real facts
 
Ejer11a.
Ejer11a.Ejer11a.
Ejer11a.
 
Papeleria
PapeleriaPapeleria
Papeleria
 
Pro eft tapping points
Pro eft tapping pointsPro eft tapping points
Pro eft tapping points
 
Payscape Loan Express
Payscape Loan ExpressPayscape Loan Express
Payscape Loan Express
 
Holiday Card
Holiday CardHoliday Card
Holiday Card
 
Week1 dq5
Week1 dq5Week1 dq5
Week1 dq5
 
Publicación1
Publicación1Publicación1
Publicación1
 
Dr APJ Award certificate 001
Dr APJ Award certificate 001Dr APJ Award certificate 001
Dr APJ Award certificate 001
 
Ficha nona
Ficha nonaFicha nona
Ficha nona
 
Wearform
WearformWearform
Wearform
 
Sports videography reel
Sports videography reelSports videography reel
Sports videography reel
 

Similar to Week3 dq1

Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
java_inheritance.pdf
java_inheritance.pdfjava_inheritance.pdf
java_inheritance.pdf
JayMistry91473
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
bharath yelugula
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
raksharao
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
Application package
Application packageApplication package
Application packageJAYAARC
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
raksharao
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
Kuntal Bhowmick
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with JavaJakir Hossain
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
Mehdi Ali Soltani
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
Java Basics
Java BasicsJava Basics
Java Basics
Emprovise
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08Terry Yoast
 

Similar to Week3 dq1 (20)

Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
java_inheritance.pdf
java_inheritance.pdfjava_inheritance.pdf
java_inheritance.pdf
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
 
Presentation 3.pdf
Presentation 3.pdfPresentation 3.pdf
Presentation 3.pdf
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
 
Application package
Application packageApplication package
Application package
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
 
Python session 7 by Shan
Python session 7 by ShanPython session 7 by Shan
Python session 7 by Shan
 
Classes2
Classes2Classes2
Classes2
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with Java
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
 
Only oop
Only oopOnly oop
Only oop
 
Java Basics
Java BasicsJava Basics
Java Basics
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 

More from amaxwell2012

Week3 dq4
Week3 dq4Week3 dq4
Week3 dq4
amaxwell2012
 
Week2 dq4
Week2 dq4Week2 dq4
Week2 dq4
amaxwell2012
 
Week2 dq3
Week2 dq3Week2 dq3
Week2 dq3
amaxwell2012
 
Week2 dq2
Week2 dq2Week2 dq2
Week2 dq2
amaxwell2012
 
Week1 dq3
Week1 dq3Week1 dq3
Week1 dq3
amaxwell2012
 
Week1 dq2
Week1 dq2Week1 dq2
Week1 dq2
amaxwell2012
 
Week 4 dq 4
Week 4 dq 4Week 4 dq 4
Week 4 dq 4
amaxwell2012
 

More from amaxwell2012 (8)

Week3 dq4
Week3 dq4Week3 dq4
Week3 dq4
 
Week2 dq4
Week2 dq4Week2 dq4
Week2 dq4
 
Week2 dq3
Week2 dq3Week2 dq3
Week2 dq3
 
Week2 dq2
Week2 dq2Week2 dq2
Week2 dq2
 
Week1 dq3
Week1 dq3Week1 dq3
Week1 dq3
 
Week1 dq2
Week1 dq2Week1 dq2
Week1 dq2
 
Week 4 dq 4
Week 4 dq 4Week 4 dq 4
Week 4 dq 4
 
Week 4 dq 3
Week 4 dq 3Week 4 dq 3
Week 4 dq 3
 

Week3 dq1

  • 1. A class contains two basic elements, state and behavior. With this being said a class must contain some sort of constructor for these two elements. On top of this there are class definition statements and object constructors for the objects that a class contains. Also a class can become a subclass of another class, and this is done in the constructor for the class itself. I will include a quick snippet of code that shows the different members of a class definition then explain them. //subclass declaration of MyClass from MySuperClass using the MyInterface interface public class MyClass extends MySuperClass implements MyInterface { //body of class includes fields (states), methods (behavior), and object declaration public int myClassState1, myClassState2; //field declarations available to all classes private int myClassState3, myClassState4; //field declarations available to this class only public MyClass (int state1, int state2, int state3, int state4) { //object constructor myClassState1 = state1; myClassState2 = state2; myClassState3 = state3; myClassState4 = state4; } public void setState1 (int newValue) { //method used to update myClassState1 myClassState1 = newValue; } public int getState1 () { //method used to return the value of myClassState1 return myClassState1; } } In the beginning of this code snippet there is a class declaration that declares the class as a sub class of MySuperClass and uses the MyInterface interface. This is the general form of a class declaration, remembering that because the MyClass is a subclass of MySuperClass, MyClass inherits the elements of MySuperClass. Next are the variables that define the state of the class. These variables are the myClassState1...2...3....4. These are the variables that are used to modify the contents of the objects of that class. Two of these variable state are private meaning that the only
  • 2. objects or classes that can use them are the MyClass. The next lines declare the object of the class that uses all four of the variables. These variable now become part of the object of the class and the object is then used to modify these state variables using the methods of the class. Next are the two methods, one is the setState1 which sets the state of the myClassState1 of the objects of the class. The other method is the getState1 which returns the value of the state of the variable myClassState1 of the object MyClass. I am not 100% but to use the objects and methods later on in the program you need to first declare an object of the class similar to this: MyClass classObjectName = new MyClass(1, 2, 3, 4); Then to use this object's methods it is done similar to this: stateHandlerVariable = classObjectName.getState1();