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

  • Financial Responsibility

    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! Now that I’m (dun dun dun) a college graduate, I feel like it’s time for be more fiscally responsible. My…

  • | | |

    Version 4.0

    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!The New TehJoey is officially launched. You may have been noticing over the last few days, when layouts were switching back…

  • The first weekend…

    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!Im fucking exhausted already. I got here friday- leadership dinner. Sat- Move in frreshmen on 3rd floors in hot sun. Then…

  • |

    QT: Increase the WordPress RSS Widget Refresh Rate

    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!While working on the redesign to this blog, I wanted to add the “Interesting Stuff” column you see just to the…

  • | |

    Casabona.Org

    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!The Official Launch! Im excited to announce, on June 1st, 2005- the official launch of Casabona.Org– a website I have been…