1. 在java中,假如我要实现一个函数getHeight(int height)返回的是传入的height
1). 在A.java文件中声明和定义函数的实现,代码如下:
public class A
{
public int getHeight(int height)
{
return height;
}
}
2).在B.java中提供主入口函数,然后调用A类中的函数getHeight,代码如下:
public class B
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
A a = new A();
a.getHeight(180);
}
}
2.对比在C++中实现同样的函数:
1). 在a.h文件中声明类和函数,实现如下:
class A
{
pubic:
int get_height(int height);
};
2).在 a.cpp文件中的进行函数的定义,代码如下:
#include "a.h"
int A::get_height(int height)
{
return height;
}
3).在 main.cpp文件中实现调用函数get_height(int height),代码如下:
#include "a.h"
void main()
{
A a;
a.get_height(180);
}