1. Trang chủ
  2. » Công Nghệ Thông Tin

Java C3. oop basic pdf

50 475 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 421 KB

Nội dung

1 Chapter 3. OOP Basic ITSS Java Programming CAO Tuan-Dung, HUT 2 Object - Oriented  Real world concepts can be modeled in a computer program  The program is made of objects with certain properties and operations that the objects can perform  It is not important how an object is implemented, but what it does  Every object is responsible for carrying out a set of related tasks 3 Object Oriented Real world Attribute Account name: Duc Binh Balance: 2.000.000 VND Deposit Debit Balance inquiry Operation request Balance inquiry I want to inquiry the balance Computer world Attribute name: Duc Binh Balance: 2.000.000 VND Deposit() Withdraw() checkBalance() operation operation Account object User object Message transmission checkBalance() 4 Class and Object  A group of objects with similar properties and behaviors is described by a class.  Class is a blueprint for an object.  A class contains fields and methods that define the behavior of the object.  A class is a description of a kind of object. 5 Class and Objects Attribute name: Duc Binh Balance: 2.000.000 VND Deposit() Withdraw() checkBalance() operation Account object of Mr Duc Binh Attribute name: Thu Lan Balance: 1.000.000 VND Deposit() Withdraw() checkBalance() operation Account object of Mrs Thu Lan Account Class (model of objects) Attribute Definition of member variable String name; long balance; void deposit(int money); void withdraw() int checkBalance() Method definition operation INSTANTIATE 6 Classes  A class can contain data declarations and method declarations int size, weight; char category; Data declarations Method declarations 7 class definition  Syntax: <modifier> class <name> { <Definition of member variable> <Definition of method> }  Example public class StudentRecord { // Definition of member variable // method definition } public class Account { // Definition of member variable // method definition } 8 Definition of member variable  Format: [Modifier] Data type Member variable name,…;  Example: public class Account { String name; // Account name long balance; // Balance : : void deposint (long money){ balance +=money; } } member variable can be used from anywhere if in the class 9 Method definition  Syntax: [Modifier] Return Value type method- name (Arguments list) { Body of method }  Example: public class Account { String name; // Account name long balance; // Balance : : void deposint (long money){ balance +=money; } } member variable can be used from anywhere if in the class 10 Variable length Argument  In the method, a variable-length argument that can pass many values can be declared. You may not pass the value to a variable-length argument.  In the method that uses a variable-length argument, we treat the passed argument as an array.  Syntax: [Modifier] Type of return value Method name (Data type name… Variable name) { Processing; } [...]... { name = pName; balance = pMoney; System.out.println(“It has 2 arguments "); System.out.print("Account name : " + name); System.out.println(“/tBalance : " + balance + "Yen"); } } 20 Solution: Overload .java class Overload { public static void main(String args[]) { Account obj = new Account(); obj.setData("Lan Anh", 100000); // Call display() method without argument obj.display(); // Call display() method... Account(); obj.display(); System.out.println(); // Generation of account object(Constructor with 2 arguments) Account obj2 = new Account(“Nam Hai", 100000); obj2.display(); } } 29 Assignment of variable  Basic data type int x = 20; int y = x;  Reference type x 20 y 20 Account obj = new Account(); Account act = obj Account Object obj act obj and act refer the same object 30 The static Modifier  We declare . 1 Chapter 3. OOP Basic ITSS Java Programming CAO Tuan-Dung, HUT 2 Object - Oriented  Real world concepts can be modeled

Ngày đăng: 28/06/2014, 03:20

TỪ KHÓA LIÊN QUAN

w