Classes

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Classes as PDF for free.

More details

  • Words: 279
  • Pages: 6
Classes in Java

Classes • All code in a Java program is part of a class • A class has two purposes – Provide functions to do work for the programmer – Represent data

• Two kinds of things found in a class – Variables store data about the class – Methods provide programmers with ways of asking the class to do work

Defining a Class class myClass { 1. Starts with the word “class” ... 2. Followed 3. Followed ... by the class by an open ... name curly bracket 4. Followed by } method and variable What name definitions. would this 5. Followed by a close file have? curly bracket

Indenting Classes • Variables and methods in a class should be indented • Close bracket at end should be indented the same as class • Open bracket can be on same line as class or next line • Classes are usually in their own file

class myClass{ void method1(){ code } }

Formatting Java Programs • Java is case sensitive. E.g. class myclass is not the same as class MyClass. • Java is white space insensitive – Can put any number of spaces or new line characters between statements – Should use spaces to indent to make programs readable

• // (two slashes) in Java start a comment: // This is a comment – Everything from the // to the end of line is ignored

Summary • Java programs are made up of classes – Classes have variables that store data – Methods do work for the programmer

• Class definitions have multiple parts. • Java is case sensitive • Comments and extra white space are ignored

Related Documents

Classes
April 2020 31
Classes
May 2020 17
Classes
July 2020 23
Classes
December 2019 38
Classes
December 2019 35
Classes
April 2020 25