Week5 - Week 5(Chapter 6 Introducing Methods Classes have...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Week 5 (Chapter 6) Introducing Methods Classes have been used since the beginning of this class. However, until now, only the most rudimentary form of a class has been used. The classes created have primarily encapsulated the init , paint , and main methods, which have been used to demonstrate the basics of the Java syntax. As you will see (in chapters 8 & 9), methods and classes are substantially more powerful than the limited ones presented to far. Here in chapter 6, my focus is on how to create simple methods that can fit inside a class. A method is conceptually similar to the subroutines or functions that you have seen in other programming languages. It is designed to receive data, process the data, and return a result. Sometimes methods are designed to do something that requires no input data, or output data (resulting in the use of the word void ). A class encapsulates (i.e., contains) two things: instance variables and methods. The topic of methods is a large one because Java gives them so much power and flexibility.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Here is the basic layout of a class: class classname { type instance-variable1; type instance-variable2; // … type instance-variableN; type methodname1(parameter-list) { // body of method } type methodname2(parameter-list) { // body of method } type methodnameN(parameter-list) { // body of method } } Here, type specifies the type of data returned by the method. If the method does not return a value, its return type must be
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 11

Week5 - Week 5(Chapter 6 Introducing Methods Classes have...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online