Java与C++的多态
没有必要用一堆绕口的形容词来描述什么叫多态,只举出几个关键点。
设:gun为父类,shootgun和pistol为gun的子类。
Java:
class gun {
void shoot() {
System.out.println("gun shoot");
}
}
class shootgun extends gun {
void shoot() {
System.out.println("shootgun shoot");
}
}
class pistol extends gun {
void shoot() {
System.out.println("pistol shoot");
}
}
C++:
class gun
{
void shoot()
{
cout << "gun shoot" << endl;
}
};
class shootgun : gun
{
void shoot()
{
cout << "shootgun shoot" << endl;
}
};
class pistol : gun
{
void shoot()
{
cout << "pistol shoot" << endl;
&n
相关文档:
http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html
Does Java pass by reference or pass by value?
Why can't you swap in Java?
By Tony
Sintes, JavaWorld.com, 05/26/00
Print
Email
Feedback
Resources
Discuss
(76)
Digg
Reddit
SlashDot
Stumble
......
//=============================输出奇数
public class OddTest {
public static boolean isOdd(int i){
return i % 2 != 0; //比较 i % 2 == 0;注: -1%2 = -1
}
public static void main(String[] args) {
for(int i = -10; i <= 10; i++) {
System.out.println(isOdd(i));
}
}
}
// ......
返回多个对象:
PROCEDURE AUTO_SEL_INVOICE_DETAIL(
P_RESULT_LIST OUT SYS_REFCURSOR) AS
BEGIN
OPEN P_RESULT_LIST FOR
SELECT DISTINCT CC.CHARGE_COLLECTION_ID CHARGE_COLLECTION_ID, CC.COLLECT_DATE COLLECT_DATE, C ......
public static void CentreWnd(Shell shell){
int width = shell.getMonitor().getClientArea().width;
int height = shell.getMonitor().getClientArea().height;
int x = shell.getSize().x;
int y = shell.getSize().y;
if (x > width) {
shell.getSize().x = width;
}
if (y > height) ......
public class EchoDefaultSystemEncoding
{
public static void main(String[] args)
{
String encoding = System.getProperty("file.encoding");
System ......