Professor Kit Romano's Web Site

 



Site Index

About Me

Welcome
Definition of Program
Variable Types
Understanding Memory
Declaring Variables
Simple Commands
Concatenation and Strings
Sleep-Threads-Try Catch
Campus Scenes
Pictures
Java simplified
Application Shell Styles
Reading Data From File
Overview of Applets
Excellent Graphics Applet
Online Reference
Nested if statements
Arrays
Sorting Arrays
Using Strings
Functions
Top 20 Replies 
First program 211
Important Class Example
JAVA in SDK Environment
Understanding OOP
OOP simple example
Recursion example
Example of Inheritance
     and use of JTextArea



*** Web Related **********
Build Student Web Page ?
What is FTP
Download WS ftp95
Download Java Plug In
Applets from jbuilder to sdk
Practice Problems

 

Programming Examples

 

 

                                                

 

OOP simple example

// sample of 2 classes , one is an application with a main method

// and the other is a simple class with 1 instance variable and 3 methods

// keep for future reference

 

package untitled14;

 

public class student

{

  protected int age; //also can make "private"

  public student()

{

    age=0;

  }

  public void setAge(int c)

{

    age=c;

  }

  public int getAge()

{

    return age;

  }

 

}

 

package untitled14;

 

import java.io.*;

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class Application1

{

   public static void main(String args[])

    {

         //how to create an object...

         student shepherd = new student(); //call to the constructor, creates the object

         shepherd.setAge(30);

         int p = shepherd.getAge();

         JOptionPane.showMessageDialog(null,"Age is "+p);

         //another option: "JOptionPane.showMessageDialog(null,"Age is "+shepherd.getAge());"

         System.exit(0);

    }

}