0% found this document useful (0 votes)
18 views

Lecture 5 Java Classes 1

This document discusses key concepts in Java classes including: 1. Classes can be declared as public or private and can extend other classes or implement interfaces. 2. Inner classes are declared within other classes and only accessible within that class. 3. Method parameters refer to the variables in the method declaration while arguments are the actual values passed when calling the method. 4. Constructors are used to initialize class instances and have the same name as the class but no return type, even void. They can call the superclass constructor using super().

Uploaded by

erah831
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lecture 5 Java Classes 1

This document discusses key concepts in Java classes including: 1. Classes can be declared as public or private and can extend other classes or implement interfaces. 2. Inner classes are declared within other classes and only accessible within that class. 3. Method parameters refer to the variables in the method declaration while arguments are the actual values passed when calling the method. 4. Constructors are used to initialize class instances and have the same name as the class but no return type, even void. They can call the superclass constructor using super().

Uploaded by

erah831
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Java Classes

Engr. Joseph R. Maiquez Week #06 July 23 2011

Class, Multiple Class


class
the keyword use to declare a class

Modifiers
public
The primary class The identifier is the same as the filename

Private
The supporting class Classes accessible only within the file

Class, Multiple Class


public class Rectangle extends Polygon implements Painter { //statements }

Class, Multiple Class


Inner classes public class EvenNumbers {

private class EvenIterator {


} }

Matching Parameters
Parameters refers to the list of variables in a method declaration Arguments are the actual values that are passed in when the method is invoked. No. of Arguments Data type of each argument must match
Casting can be used to match arguments for different objects as long as they are compatible (is a relationship)

Passing Objects
Passing hadles/reference Simple Readable Flexible

public void addStudent (Student stud) { // statement }

Constructor
Used to create an instance of a class and initializes the instance variables Contructor name is the same as the class name Default constructor has no parameter Default contructor is only created if there is no constructors It has no return type (not even void) The super() is used to call the superclass constructor.

Class Constant and Local Variables


final
Reserve word used to declare constant variables Most constant variables are declared public and static

static
Reserve word / modifier used to declare class variables

Instance variables
Class local variables Values are different in each instance

Calling Methods of Same Class


public class Ticket { int ticketNumber = 0; public Ticket() { ticketNumber = generateTicketNumber(); } private int generateTicketNumber() { } }

Converting Class to Main Class


public static void main(String[] args) { //Contructor }

You might also like