Creating a Method

Creating a Method - Parameters -pass a parameter to the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Creating a Method - declare method o syntax: visibility returnType name(parameterList) visibility determines access (public/private) if nothing returned: void example: public void drawSquare(); - name method Adding a method to a class - type method at end of code o before last } - compile files before testing in interactions pane o clears all old variables Main methods - when you execute a class you can have a main method - main method: class (static) method o takes an array of strings o class (static) method because no objects of class exist yet
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Parameters -pass a parameter to the method o parameter lists specify what type of thing is passed name to use to refer to the value in the method o ie: public void drawSquare(int width); Subclasses -inherits the methods and field o Turtle class is a subclass of SimpleTurtle o public class Turtle extends SimpleTurtle Can add new variables and new methods -Classes can subclass another class in Java and Alice...
View Full Document

This note was uploaded on 02/28/2011 for the course CSCI 053 taught by Professor Sibert during the Fall '10 term at GWU.

Ask a homework question - tutors are online