class People { float hello(int a,int b) { return a+b; } float hello(long a,int b) { return a-b; } double hello(double a,int b) { return a*b; } } public class Example4_12 { public static void main(String args[]) { People tom = new People(); System.out
其实这里没什么可说哦,c++的语法大同小异.先看一段代码. class Program { public static void Test(int a) { Console.WriteLine("只有一个参数a=={0}", a); } public static void Test(int a, int b = 5) { Console.WriteLine("有两个参数a=={0},b=={1}", a, b); } static void Main() { Te
1.方法重载 1)方法的签名 方法的签名包含方法名和参数列表 一个类中,不可以有两个方法的签名完全相同,即一个类中不能有两个方法的方法名和参数列表都一样. public class Test{ public void print(int x){...}; public void print(int x){...}; //编译错误,方法签名不能一样 } public class Test{ public void print(int x){...}; public boolean print(i
面向对象三大特点:封装.继承.多态 封装概念 ① 将东西包装在一起,然后以新的完整形式呈现出来: 将方法和字段一起包装到一个单元中,单元以类的形式实现; ② 信息隐藏,隐藏对象的实现细节,不让外部直接访问到; ③ 将数据和方法包装进类中,加上具体实现的隐藏,共同被称作封装,其结果是一个同时带有特征和行为的数据类型; ④ 定义类,定义其属性.方法的过程称为封装类; 信息隐藏式OOP最重要的功能之一,也是使用访问修饰符的原因; 信息隐藏的原因包括: ① 对模块的任何实现细节所作的
一.课前引言 请看一下代码,你发现什么特殊之处了吗? public class MethodOverload { public static void main(String[] args) { System.out.println("The square of integer 7 is " + square(7)); System.out.println("\nThe square of double 7.5 is " + square(7.5)); } pu
类的继承 父类-子类 关键字 extends 新建一个父类 public class Person { private String name; private int age; public void run() { System.out.println("Person run"); } } public class Student extends Person { public void run()