Classes
Download
1 / 33

Classes - PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on

Classes. By Cheryl Slivinski. class. A construct that is used as a blueprint to create objects of that class. classes. This blueprint describes the state and behavior that the objects of the class all share. An object is also known as an instance of the class. Qualifiers.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Classes' - mostyn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Classes

Classes

By Cheryl Slivinski


Class

class

A construct that is used as a blueprint to create objects of that class.


Classes1
classes

  • This blueprint describes the state and behavior that the objects of the class all share.

  • An object is also known as an instance of the class.


Qualifiers
Qualifiers

  • Public: access to all classes

  • Private: access only to the class to which they belong.

  • Protected: access only to the class to which they belong, and any subclasses


Methods
Methods

  • a method is a subroutine that is exclusively associated either with a class (in which case it is called a class method or a static method) or with an object (in which case it is an instance method)


Methods1
Methods

  • A constructor method, supported by many languages, is called automatically upon the creation of an instance of a class. Some languages have a special syntax for constructors.

  • In Java, C++, C#, ActionScript, and PHP constructors have the same name as the class of which they are a member


Methods2
Methods

  • A destructor method (i.e. a special instance method that is called automatically upon the destruction of an instance of a class), is implemented in some languages.

  • A destructor method (i.e. a special instance method that is called automatically upon the destruction of an instance of a class), is implemented in some languages.


Methods3
Methods

  • A destructor method (i.e. a special instance method that is called automatically upon the destruction of an instance of a class), is implemented in some languages.


Methods4
Methods

  • An accessor method is a method that is usually small, simple and provides the sole means for the state of an object to be accessed (retrieved) from other parts of a program.


Methods5
Methods

  • An abstract method is a dummy code method which has no implementation. It is often used as a placeholder to be overridden later by a subclass of or an object prototyped from the one that implements the abstract method. In this way, abstract methods help to partially specify a framework.


Methods6
Methods

  • An Instance method, in a typical implementation, is passed a hidden reference (e.g. this, self or Me) to the object (whether a class or class instance) it belongs to, so that it can access the data associated with it.


User defined class
User Defined Class

  • User defined classes combine the data and methods that operate on that data


Syntax for defining a class
Syntax for defining a class:

  • accessModifiener class ClassName {

           //class definition goes here;

}


Encapsulation
Encapsulation

  • Encapsulation conceals the functional details of a class from objects that send messages to it.

  • Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in the future, thereby allowing those changes to be made more easily, that is, without changes to clients.


Inheritance
Inheritance

  • Inheritance allows the programmer to treat derived class members just like their parent class's members. This type of relationship is called child-Parent or is-a relationship. "Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.


Polymorphism
Polymorphism

  • Polymorphism is a process in which a class has all the state and behavior of another class.More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). Each subclass overrides the speak() method inherited from the parent class Animal.



History
History

  • Started in 1991

  • Designed for interactive TV

  • Called ‘Oak’ then ‘Green’

  • Goal

  • Released in 1995

  • ‘Write once, run anywhere’


Types
Types

  • Java SE

  • Java EE

  • Java ME or J2ME


Running java
Running Java

  • Java Runtime Environment (JRE)

  • Java Virtual Machine (JVM)

  • Java Development Kit (JDK)


Editing and compiling
Editing and Compiling

  • NetBeanswww.netbeans.org

  • Eclipse www.eclipse.org


Hello world
Hello World

package hello;

/*

*by cheryl

*/

Public class HelloWorld {

Public static void main(String[] args) {

//print

System.out.println (“Hello World”); } }


Data types
Data Types

  • byte

  • short

  • int

  • long

  • float

  • double

  • boolean

  • char


Control structures
Control Structures

  • If/else

  • For

  • While

  • Do/while

  • Switch/case

  • Break

  • continue


Operators
Operators

  • *,/,%,+,-

  • Expr++, --expr

  • ==

  • !=

  • &&

  • ||

  • + can be overloaded


Classes2
Classes

<modifier> class <ClassName>

{

//class body

}


Member variables
Member Variables

<modifier> <type> <name>

public class Car {

private int speed;

private string make;

private static intnumberOfCars;

private static final int NUMBER_OF_WHEELS

}


Methods7
Methods

<modifiers> <returnType> <methodName>

(parameters)


Constuctors
Constuctors

  • Are Methods

  • Same name as class

  • No return type


Packages
Packages

  • Way of grouping related classes and level of access security

    cellphone

    cellphone.gui

    cellphone.database


J ava lang object
java.lang.Object

  • Top level class in hierarchy

  • Defines several methods

  • Ex. Public String toString()


Access modifiers
Access Modifiers

  • public

  • protected

  • private

  • No modifier


Naming conventions
Naming Conventions

  • packages ex package mypackage

  • classes ex class MyPackage

  • methods ex private void myPackage

  • variables ex intmyPackage

  • Constants ex static final char MYPACKAGE=12


ad