1 / 11

Classes in Java

Classes in Java. Introduction. The entire concept of Object Oriented Programming is not about objects, its about class. Because we use classes to create objects….. The class describes what an object will be. It’s a blue print of an object and it is the description and definition of an object.

adunbar
Download Presentation

Classes in Java

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Classes in Java

  2. Introduction The entire concept of Object Oriented Programming is not about objects, its about class. Because we use classes to create objects….. The class describes what an object will be. It’s a blue print of an object and it is the description and definition of an object.

  3. Blue print example class: Blue print

  4. Creating Object Using blue print (class) we create object

  5. One class, multiple objects…. Once a class is created, using single class we can create any number of objects.

  6. How to Create a class? To create a class first, we need to find the following…. type Name - What is it ? Student, Employee, BankAccount, Document, Car, Box….. Properties, data Attributes - What describes it ? name, salary, balance, size, color, width….. operations Behavior - What can it do ? read, play, search, save, create, print, close, open, deposit…..

  7. Example class Creating a Bank Account class Name - BankAccount Attributes - name, AccNo, balance, dateOpened, accountType, branch Behavior - open( ), close( ), deposit( ), withdraw( )

  8. Example class A class is represented in a rectangle box with 3 rows.. Creating objects is called instantiation Jayasree 67894 15000 23/5/2014 Current Sec’bad open() close() deposit() withdraw() ClassName BankAccount Rahul 12345 1500 3/5/2014 Savings Sec’bad open() close() deposit() withdraw() Asha 54321 1800 3/6/2013 Savings HYD open() close() deposit() withdraw() List Of Attributes . . name accountNumber balance dateOpened accountType branch List Of Operations . . open( ) close( ) deposit( ) withdraw( ) RahulAcct AshaAcct JayaAcct class Object (instance)

  9. Creating object of a class Syntax for object creation classBankAccount ClassNameobjectName = new ClassName( ); BankAccount classBankAccount • { • String name ; • int accountNumber; • double balance ; • String dateOpened; • String accountType; • String branch; name accountNumber balance dateOpened accountType branch • { • String name ; • int accountNumber; • double balance ; • String dateOpened; • String accountType; • String branch; Example for object creation BankAccountrahulAcct = new BankAccount( ); • void open( ){….} • void close( ){….} • void deposit( ){….} • void withdraw( ){….} BankAccountashaAcct = new BankAccount( ); open( ) close( ) deposit( ) withdraw( ) • void open( ){….} • void close( ){….} • void deposit( ){….} • void withdraw( ){….} BankAccountjayaAcct = new BankAccount( ); • } • }

  10. Class Structure in programming…. classBankAccount BankAccount classBankAccount • { • String name ; • int accountNumber; • double balance ; • String dateOpened; • String accountType; • String branch; name accountNumber balance dateOpened accountType branch • { • String name ; • int accountNumber; • double balance ; • String dateOpened; • String accountType; • String branch; • void open( ){….} • void close( ){….} • void deposit( ){….} • void withdraw( ){….} open( ) close( ) deposit( ) withdraw( ) • void open( ){….} • void close( ){….} • void deposit( ){….} • void withdraw( ){….} • } • }

  11. Classes inJava Programming Next….

More Related