Types of classes

Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don't hold it against me. One of the perils of having a 20+ year old website!

Today and over the last couple of days we have been talking about classes in Java. I’m fairly certain I understand them enough to now talk about them here. Tonight I will introduce them and continue the discussion later.

Basically, a class “consists of a collection of types of encapsulated instance variables and types of methods, possibly with implementation of those types together with a constructor function that can be used to create objects of the class. A class is a cohesive package that consists of a particular kind of compile-time metadata. A Class describes the rules by which objects behave; these objects are referred to as “instances” of that class. …” In basic terms, it is the blue prints of an object. Inside of a class, you will find instance varibles with values, methods to manipulate these variables, and constructors of those objects. If we were to make a class called Student , it might look something like this:

public class Student{

private String name;
private int age;
private float gpa;
private char status;

public Student (String stuName, int stuAge, float stuGpa, char stuStat){
name= stuName;
age= stuAge;
gpa= stuGPA
status= stuStat

}
public Student(){
name= “”;
age= 0;
gpa= 0.0;
status= null;
}

}

This class has 2 methods- both constructors- and 4 instance variables in it. The variables are initialized, but have no values. This is where the constructors come in. The first constructor for Student has 4 arguments sent to it. One for name, age, gpa and status. The constructor takes these 4 values sent by the client (NOT necessarily a user) and applies them to our 4 instance variables. The second constructor, which has no arguments, simply creates an object where all of them variables are set to nothing values.

For right now we only have constructors in our class. Next time, I will talk about other possible methods for our Student class, and subclasses that might inherit out Student class. Later

PS- to read ahead, and check out the counter class we have been working on in class, you can find it here
I know this was a little rushed, so if you have any questions, feel free to comment them or email me.

Similar Posts

  • |

    Using GMail for files

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! As a college student I am often bouncing around from PC to PC as I go through my day on…

  • | |

    What I Learned in College

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! Over at Nettuts, they’ve posted an article titled, “Should You Attend University for Web Development”. Reading the article, I found…

  • New Facebook Fun

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! For all the people out there with Facebook, an online social site for college and now high school students all…

  • Its been a while

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website!Yes yes, I haven’t written in a while. I have been busy, and it does not look to slow down any,…

  • | |

    Directory Handler at Theme Forest

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website!I’m happy to announce my first Theme Forest component, Directory Handler. it’s a simple set of 2 classes that handle (in…

  • | | |

    10+ iPad Apps for Students

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! With college starting up again after the holiday break and what I’m sure is many students heading back to school…