my day2

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:使用至少两个属性和两个方法重载

  1. package com.zjm.www.day10;  
  2. /**+ 
  3.  *  
  4.  * 动物练习 
  5.  * @author Zjm 
  6.  * 
  7.  */  
  8. public class Ex_animal {  
  9.   
  10.     public static void main(String[] args) {  
  11.         // TODO Auto-generated method stub  
  12.   
  13.         Animal an1 = new Animal("兔子","草",5);  
  14.         Animal an2 = new Animal();  
  15.         Animal an3 = new Animal(an1,an2);  
  16.         an2.all(an3);  
  17.     }  
  18. }  
  19. class Animal{  
  20.     String name;  
  21.     String eat;  
  22.     int weight;  
  23.     public Animal() {  
  24.         this.name = name;  
  25.         this.eat = "猪蹄";  
  26.         this.weight = 12;  
  27.     }  
  28.     public Animal(Animal a,Animal b) {  
  29.         this.name = b.name;  
  30.         this.eat = a.eat;  
  31.         this.weight = b.weight;  
  32.           
  33.     }  
  34.     public Animal(String name,String eat,int weight) {  
  35.         this.name = name;  
  36.         this.eat = eat;  
  37.         this.weight = weight;  
  38.     }  
  39.     public Animal(String name,int weight) {  
  40.         this.name = name;  
  41.         this.weight = weight;  
  42.     }  
  43.     public void eat1() {  
  44.         System.out.println("这个动物喜欢吃" + this.eat);  
  45.     }  
  46.     public void run() {  
  47.         System.out.println("这个动物会跑");  
  48.     }  
  49.     public void all(Animal an) {  
  50.         System.out.println("这是一只 " + this.name + ",它喜欢吃 " + an.eat + ",它重 " + an.weight +" 斤");  
  51.     }  
  52. }  
  1. package com.lenovo.www.day10;  
  2.   
  3. /** 
  4.  * 测试类 
  5.  *  
  6.  * @author lenovo64 
  7.  *这只小狗是小白,白色正在和那只小猫叫做小黑,黑色在打架 
  8.  *获胜的动物是黑色 
  9.  */  
  10. public class Test {  
  11.     public static void main(String[] args) {  
  12.   
  13.         Animal dog = new Animal("小黑""小猫""黑色");  
  14.         Animal cat = new Animal("小白""小狗""白色");  
  15.         String s = dog.play(cat, dog);  
  16.         System.out.println("获胜的动物是" + s);  
  17.     }  
  18. }  
  19.   
  20. class Animal {  
  21.     String name;  
  22.     String kind;  
  23.     int age;  
  24.     String color;  
  25.     long animalID;  
  26.     String date;  
  27.   
  28.     public Animal(String name, String kind) {  
  29.         this.name = name;  
  30.         this.kind = kind;  
  31.     }  
  32.   
  33.     public Animal(String name, String color, String kind) {  
  34.         this.name = name;  
  35.         this.color = color;  
  36.         this.kind = kind;  
  37.     }  
  38.   
  39.     public Animal(String name, int age, long animalID) {  
  40.         this.age = age;  
  41.         this.animalID = animalID;  
  42.     }  
  43.   
  44.     public String play(Animal dog, Animal cat) {  
  45.         System.out.println("这只" + dog.color + "是" + dog.name + "," + dog.kind + ",正在和那只" + cat.color + "叫做" + cat.name  
  46.                 + "," + cat.kind + ",在打架");  
  47.         return cat.kind;  
  48.     }  
  49. }  

实参:调用方法的时候传递的参数叫实参。

形参:定义方法时,括号里的参数叫形参。

 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:


猜你喜欢

转载自blog.csdn.net/weixin_42034170/article/details/80258369
my