1:什么是类?
类就是具有相同属性和方法的一组对象的集合。
2:什么是对象?
用来描述客观事物的一个实体由一组属性和方法构成。
3:方法和属性是什么?
方法:对象的执行的操作
属性:对象具有的特征
4:什么是方法重载?(代码)
同一个类中的2个或2个以上的方法可以有同一个名字,只要它们的参数声明不同即可。在这种情况下,该方法就被称为重载, 这个过程称为方法重载。
package lypshizhu;
public class Essay {
public void writeEssay(String a,int b) {
System.out.println("用"+b+"只笔写文章");
}
public void writeEssay(int a,String b) {
System.out.println("用"+a+"张纸写文章");
}
public void writeEssay(String a,String b) {
System.out.println("用铅笔"+"写在纸上");
}
public String writeEssay(String computer) {
return computer;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Essay s = new Essay();
s.writeEssay("",6);
s.writeEssay(5,"");
s.writeEssay("","");
String c = s.writeEssay("联想电脑");
System.out.println(c);
}
}
5:Eclipse常用的快捷键有哪些?
sysout+alt+/=System.out.println();
shift+crtl+o=导包
shift+crtl+f=排版
/**+enter=注释
6:使用至少两个属性和两个方法重载
- package com.zjm.www.day10;
- /**+
- *
- * 动物练习
- * @author Zjm
- *
- */
- public class Ex_animal {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Animal an1 = new Animal("兔子","草",5);
- Animal an2 = new Animal();
- Animal an3 = new Animal(an1,an2);
- an2.all(an3);
- }
- }
- class Animal{
- String name;
- String eat;
- int weight;
- public Animal() {
- this.name = name;
- this.eat = "猪蹄";
- this.weight = 12;
- }
- public Animal(Animal a,Animal b) {
- this.name = b.name;
- this.eat = a.eat;
- this.weight = b.weight;
- }
- public Animal(String name,String eat,int weight) {
- this.name = name;
- this.eat = eat;
- this.weight = weight;
- }
- public Animal(String name,int weight) {
- this.name = name;
- this.weight = weight;
- }
- public void eat1() {
- System.out.println("这个动物喜欢吃" + this.eat);
- }
- public void run() {
- System.out.println("这个动物会跑");
- }
- public void all(Animal an) {
- System.out.println("这是一只 " + this.name + ",它喜欢吃 " + an.eat + ",它重 " + an.weight +" 斤");
- }
- }
- package com.lenovo.www.day10;
- /**
- * 测试类
- *
- * @author lenovo64
- *这只小狗是小白,白色正在和那只小猫叫做小黑,黑色在打架
- *获胜的动物是黑色
- */
- public class Test {
- public static void main(String[] args) {
- Animal dog = new Animal("小黑", "小猫", "黑色");
- Animal cat = new Animal("小白", "小狗", "白色");
- String s = dog.play(cat, dog);
- System.out.println("获胜的动物是" + s);
- }
- }
- class Animal {
- String name;
- String kind;
- int age;
- String color;
- long animalID;
- String date;
- public Animal(String name, String kind) {
- this.name = name;
- this.kind = kind;
- }
- public Animal(String name, String color, String kind) {
- this.name = name;
- this.color = color;
- this.kind = kind;
- }
- public Animal(String name, int age, long animalID) {
- this.age = age;
- this.animalID = animalID;
- }
- public String play(Animal dog, Animal cat) {
- System.out.println("这只" + dog.color + "是" + dog.name + "," + dog.kind + ",正在和那只" + cat.color + "叫做" + cat.name
- + "," + cat.kind + ",在打架");
- return cat.kind;
- }
- }
实参:调用方法的时候传递的参数叫实参。
形参:定义方法时,括号里的参数叫形参。
7:JDK和JRE 分别是什么意思?
JDK: Java Development Kits =“java开发工具集 ”
JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境。SDK是Software Development Kit 一般指软件开发包,可以包括函数库、编译程序等。
JDK就是Java Development Kit
JRE是Java Runtime Enviroment是指Java的运行环境,是面向Java程序的使用者,而不是开发者。
JRE: Java Running Environment = "java运行环境“
8:String是基本数据类型么?
不是 final类
9:float f = 3.4 这种格式是正确的么?
不是 float f= 3.4f;
10:&和&&有什么区别?
两者都表示“与”运算,但是&&运算符第一个表达式不成立的话,则发生短路,后面的表达式不运算,直接返回。而&对所有表达式都得判断。
11:怎样理解JAVA 的可移植性?
可移植性是指java程序不必重新编译就能在任何平台上运行。java源程序经编译后产生的二进制代码是一种与系统结构无关的指令集和,通过java虚拟机,可以在不同平台上运行。因此java语言编写的程序只要做较少的修改,甚至有时候根本不需要修改,就可以在Windows、MacOSX、UNIX等平台上运行,充分体现了”一次编译,到处运行“的特性。
12:表格
private default protected public
同一个类中 √ √ √ √
同一个包中 √ √ √
子类中 √ √
全局范围 √
13: