Ex7ManyMethods

Ex7ManyMethods - { // declare our variables ManyMethodClass...

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

View Full Document Right Arrow Icon
/* ManyMethodClass * * This class uses increasingly sophisticated methods in order to gauge where * students are getting lost */ public class ManyMethodClass { String name; // instance variable public void printFirstMessage() { System.out.println("Hello! Welcome!"); } public void printSecondMessage(String n) { System.out.println("Hello, "+n); } public void setName(String n) { name = n; } public void printThirdMessage() { System.out.println("My name is "+name); } } /* CallManyMethodClass * * This class uses the ManyMethodClass, calling different methods, in order * to find out where students are lost */ public class CallManyMethodClass { public static void main(String args[])
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { // declare our variables ManyMethodClass myObject, myOtherObject; // allocate our variables myObject = new ManyMethodClass(); myOtherObject = new ManyMethodClass(); // call some methods on myObject myObject.printFirstMessage(); // call a method that expects a parameter myObject.printSecondMessage("Mei"); myObject.printSecondMessage("John"); // set an instance variable myObject.setName("Vlasia"); myOtherObject.setName("DaiChi"); // call some methods that use instance variables myObject.printThirdMessage(); myOtherObject.printThirdMessage(); } // end of main } // end of CallManyMethodClass...
View Full Document

Ask a homework question - tutors are online