freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

java程序設(shè)計教學(xué)課件5(編輯修改稿)

2025-06-06 18:25 本頁面
 

【文章內(nèi)容簡介】 intCircle(Circle c) { (radius ( + () + ) and number of Circle objects ( + () + ))。 } } 41 ? 、 變量的作用域 我們已經(jīng)知道類體分為兩部分,變量定義部分所定義的變量被稱為類的成員變量。 局部變量 : 在方法體中定義的變量和方法的參數(shù)被稱為局部變量。 成員變量在整個類內(nèi)都有效,局部變量只在定義它的方法內(nèi)有效。 42 如果局部變量的名字與成員變量的名字相同,則成員變量被 隱藏 ,即這個成員變量在這個方法內(nèi)暫時失效。 class Tom{ int x=98,y。 void f(){ int x=3。 y=x。//y得到的值是 3,不是 f 中沒有” int x=3?!闭Z句 ,y 的值將是 98. } } 43 this 關(guān)鍵字 this 關(guān)鍵字可以出現(xiàn)在類的實(shí)例方法中,代表使用該方法的當(dāng)前對象。 例: class trangle{ double a,b,c。 trangle(double a,double b,double c){ setABC(this,a,b,c)。 } void setABC( trangle ,double a ,double b ,double c){ =a。 =b。 =c。 } } class Example4_10{ public static void main(String args[]){ trangle tra=new trangle(3,4,5)。 (三角形型的三邊是 :++,++,++,)。 } } 44 public class Rational { private long numerator = 0。 private long denominator = 1。 // Default constructor public Rational() { this(0, 1)。 } 45 // Construct a rational with specified numerator and denominator public Rational(long numerator, long denominator) { long gcd = gcd(numerator, denominator)。 = numerator/gcd。 = denominator/gcd。 } 46 private long gcd(long n, long d) { long t1 = (n)。 long t2 = (d)。 long remainder = t1%t2。 while (remainder != 0) { t1 = t2。 t2 = remainder。 remainder = t1%t2。 } return t2。 } 47 // Getter method for numerator public long getNumerator() { return numerator。 } public long getDenominator() { return denominator。 } 48 // Add a rational number to this rational public Rational add(Rational secondRational) { long n=numerator*() + denominator*()。 long d = denominator*()。 return new Rational(n, d)。 } // Subtract a rational number from this rational public Rational subtract(Rational secondRational) { long n = numerator*() denominator*()。 long d = denominator*()。 return new Rational(n, d)。 } 49 // Multiply a rational number to this rational public Rational multiply(Rational secondRational) { long n = numerator*()。 long d = denominator*()。 return new Rational(n, d)。 } // Divide a rational number from this rational public Rational divide(Rational secondRational) throws RuntimeException { if (() == 0) throw new RuntimeException(Denominator cannot be zero)。 long n = numerator*()。 long d = denominator*()。 return new Rational(n, d)。 } 50 // Override the toString() method public String toString() { if (denominator == 1) return numerator + 。 else return numerator + / + denominator。 } } 51 public class TestRationalClass { public static void main(String[] args) { // Create and initialize two rational numbers r1 and r2. Rational r1 = new Rational(4, 2)。 Rational r2 = new Rational(2, 3)。 // Display results (() + + + () + = + ((r2)).toString())。 (() + + () + = + ((r2)).toString())。 (() + * + () + = + ((r2)).toString())。 (() + / + () + = + ((r2)).toString())。 } } 52 字符串的分類 ? String和 StringBuffer兩個類; ? 在運(yùn)行中值不會改變的字符串,用 String類存儲;值會改變的字符串用 StringBuffer類來存儲。 ? 兩個類都有 final修飾,這樣可以優(yōu)化字符串的操作。 53 String類 ? String類的定義原型 : public final class extends { … } 54 字符串常量 ? 字符串常量屬于 String類型 。 ? 相同的字符串常量屬于同一個對象,占用同一塊空間 ,例如 : // 程序 public class TestConstString{ public static void main(String args[ ]) { String str1=Hello, str2=Hello。 (str1==str2)。 (Java==Java)。 } } 56 創(chuàng)建 String類對象 ? 用 new運(yùn)算符,并調(diào)用構(gòu)造函數(shù)創(chuàng)建這種類型的對象,常見構(gòu)造函數(shù)如下: 1. public String( ) 采用該構(gòu)造函數(shù)創(chuàng)建一個不含字符的空對象 。 例如: String str =new String( )。 2. public String(char value
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1