?? 《java就業(yè)培訓教程》_張孝祥_書內(nèi)源碼_04.txt
字號:
《Java就業(yè)培訓教程》 作者:張孝祥 書中源碼
網(wǎng)址:www.itcast.cn
《Java就業(yè)培訓教程》P127源碼
程序清單:Student.java
class Person
{
public String name;
public int age;
public Person(String name,int age)
{
this.name=name;
this.age=age;
}
public Person() //如果不寫這個構(gòu)造函數(shù),看看對類Student有什么影響。
{
}
public void getInfo()
{
System.out.println(name);
System.out.println(age);
}
}
class Student extends Person
{
public void study()
{
System.out.println("Studding");
}
public static void main(String[] args)
{
Person p=new Person();
p.name="person";
p.age=30;
p.getInfo();
Student s=new Student();
s.name="student";
s.age=16;
s.getInfo();
s.study();
}
}
《Java就業(yè)培訓教程》P135源碼
interface Animal extends Runner
{
void breathe();
}
class Fish implements Animal
{
public void run()
{
System.out.println("fish is swimming");
}
public void breathe()
{
System.out.println("fish is bubbling");
}
}
abstract LandAnimal implements Animal
{
public void breathe()
{
System.out.println("LandAnimal is breathing");
}
}
《Java就業(yè)培訓教程》P138源碼
程序清單:C.java
class A
{
public void func1()
{
System.out.println("A func1 is calling");
}
public void func2()
{
func1();
}
}
class B extends A
{
public void func1()
{
System.out.println("B func1 is calling");
}
public void func3()
{
System.out.println("B func3 is calling");
}
}
class C
{
public static void main(String [] args)
{
B b=new B();
A a = b;
callA(a);
callA(new B());
}
public static void callA(A a)
{
a.func1();
a.func2();
}
}
《Java就業(yè)培訓教程》P141源碼
程序清單:Student.java
class Student
{
String name;
int age;
boolean equals(Object obj)
{
Student st=null;
if(obj instanceof Student)
st = (Student)obj;
else
return false;
if(st.name==this.name && st.age==this.age)
return true;
else
return false;
}
public static void main(String[] args)
{
Student p=new Student();
Student q=new Student();
p.name="xyz";
p.age=13;
q.name="xyz";
q.age=13;
if(p.equals(q))
System.out.println("p 與 q 相等");
else
System.out.println("p 與 q 不等");
}
}
《Java就業(yè)培訓教程》P144源碼
程序清單:Interface.java
interface PCI
{
void start();
void stop();
}
class NetworkCard implements PCI
{
public void start()
{
System.out.println("Send ...");
}
public void stop()
{
System.out.println("Network Stop.");
}
}
class SoundCard implements PCI
{
public void start()
{
System.out.println("Du du...");
}
public void stop()
{
System.out.println("Sound Stop.");
}
}
class MainBoard
{
public void usePCICard(PCI p)
{
p.start();
p.stop();
}
}
class Assembler
{
public static void main(String [] args)
{
MainBoard mb=new MainBoard();
NetworkCard nc=new NetworkCard();
mb.usePCICard(nc);
SoundCard sc=new SoundCard();
mb.usePCICard(sc);
}
}
《Java就業(yè)培訓教程》P149源碼
public class TestException
{
public static void main(String [] args)
{
try
{
int reslut = new Test().devide( 3, 0 );
System.out.println("the result is" + reslut );
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("program is running here ,that is normal !");
}
}
class Test
{
public int devide(int x, int y)
{
int result = x/y;
return x/y;
}
}
《Java就業(yè)培訓教程》P154源碼
public class TestException
{
public static void main(String [] args)
{
try
{
int result = new Test().devide( 3, 0 );
//int result = new Test().devide( 3, -1 );
//int result = new Test().devide( 3, 1 );
System.out.println("the result is " + result );
}
catch(DevideByMinusException e)
{
System.out.println("program is running into"+
"DevideByMinusException");
System.out.println(e.getMessage());
System.out.println("the devisor is " +
e. getDevisor());
}
catch(ArithmeticException e)
{
System.out.println("program is running into"+
"DevideByMinusException");
System.out.println(e.getMessage());
}
catch(Exception e)
{
System.out.println("program is running into"+
"other unknowned Exception");
System.out.println(e.getMessage());
}
System.out.println("program is running here ,that is normal !");
}
}
《Java就業(yè)培訓教程》P158源碼
package org.it315;
public class TestPackage
{
public static void main(String [] args)
{
new Test().print();
}
}
class Test
{
public void print()
{
System.out.println("the program is demostrating how to using package!");
}
}
下載所得:
《Java就業(yè)培訓教程》P127源碼
程序清單:Student.java
class Person
{
public String name;
public int age;
public Person(String name,int age)
{
this.name=name;
this.age=age;
}
public Person() //如果不寫這個構(gòu)造函數(shù),看看對類Student有什么影響。
{
}
public void getInfo()
{
System.out.println(name);
System.out.println(age);
}
}
class Student extends Person
{
public void study()
{
System.out.println("Studding");
}
public static void main(String[] args)
{
Person p=new Person();
p.name="person";
p.age=30;
p.getInfo();
Student s=new Student();
s.name="student";
s.age=16;
s.getInfo();
s.study();
}
}
《Java就業(yè)培訓教程》P135源碼
interface Animal extends Runner
{
void breathe();
}
class Fish implements Animal
{
public void run()
{
System.out.println("fish is swimming");
}
public void breathe()
{
System.out.println("fish is bubbling");
}
}
abstract LandAnimal implements Animal
{
public void breathe()
{
System.out.println("LandAnimal is breathing");
}
}
《Java就業(yè)培訓教程》P138源碼
程序清單:C.java
class A
{
public void func1()
{
System.out.println("A func1 is calling");
}
public void func2()
{
func1();
}
}
class B extends A
{
public void func1()
{
System.out.println("B func1 is calling");
}
public void func3()
{
System.out.println("B func3 is calling");
}
}
class C
{
public static void main(String [] args)
{
B b=new B();
A a = b;
callA(a);
callA(new B());
}
public static void callA(A a)
{
a.func1();
a.func2();
}
}
《Java就業(yè)培訓教程》P141源碼
程序清單:Student.java
class Student
{
String name;
int age;
boolean equals(Object obj)
{
Student st=null;
if(obj instanceof Student)
st = (Student)obj;
else
return false;
if(st.name==this.name && st.age==this.age)
return true;
else
return false;
}
public static void main(String[] args)
{
Student p=new Student();
Student q=new Student();
p.name="xyz";
p.age=13;
q.name="xyz";
q.age=13;
if(p.equals(q))
System.out.println("p 與 q 相等");
else
System.out.println("p 與 q 不等");
}
}
《Java就業(yè)培訓教程》P144源碼
程序清單:Interface.java
interface PCI
{
void start();
void stop();
}
class NetworkCard implements PCI
{
public void start()
{
System.out.println("Send ...");
}
public void stop()
{
System.out.println("Network Stop.");
}
}
class SoundCard implements PCI
{
public void start()
{
System.out.println("Du du...");
}
public void stop()
{
System.out.println("Sound Stop.");
}
}
class MainBoard
{
public void usePCICard(PCI p)
{
p.start();
p.stop();
}
}
class Assembler
{
public static void main(String [] args)
{
MainBoard mb=new MainBoard();
NetworkCard nc=new NetworkCard();
mb.usePCICard(nc);
SoundCard sc=new SoundCard();
mb.usePCICard(sc);
}
}
《Java就業(yè)培訓教程》P149源碼
public class TestException
{
public static void main(String [] args)
{
try
{
int reslut = new Test().devide( 3, 0 );
System.out.println("the result is" + reslut );
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("program is running here ,that is normal !");
}
}
class Test
{
public int devide(int x, int y)
{
int result = x/y;
return x/y;
}
}
《Java就業(yè)培訓教程》P154源碼
public class TestException
{
public static void main(String [] args)
{
try
{
int result = new Test().devide( 3, 0 );
//int result = new Test().devide( 3, -1 );
//int result = new Test().devide( 3, 1 );
System.out.println("the result is " + result );
}
catch(DevideByMinusException e)
{
System.out.println("program is running into"+
"DevideByMinusException");
System.out.println(e.getMessage());
System.out.println("the devisor is " +
e. getDevisor());
}
catch(ArithmeticException e)
{
System.out.println("program is running into"+
"DevideByMinusException");
System.out.println(e.getMessage());
}
catch(Exception e)
{
System.out.println("program is running into"+
"other unknowned Exception");
System.out.println(e.getMessage());
}
System.out.println("program is running here ,that is normal !");
}
}
《Java就業(yè)培訓教程》P158源碼
package org.it315;
public class TestPackage
{
public static void main(String [] args)
{
new Test().print();
}
}
class Test
{
public void print()
{
System.out.println("the program is demostrating how to using package!");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -