1:參数传递的值传递与引用传递

A:值传递:基本数据类型传递都是值传递



B:引用传递(地址传递):对象数据类型都是引用传递。

2:类变量与成员变量(实例变量,对象变量)

类变量:通过类名调用,类变量被全部的实例共享。



final static int MAX = 20;//Java中定义常量







对象变量:通过对象调用(对象必须new出来)。

3:类方法与成员方法(实例方法,对象方法)

类方法:通过类名调用,在类方法中不能使用thiskeyword。

由于this代表当前对象。

成员方法:通过对象调用(对象必须new出来)。

4:

  构造方法

  销毁方法(finalize)

销毁方法是在对象被销毁的时候进行调用的。

当一个对象在堆区没有一个明白的引用指向它的时候,Java虚

拟机觉得该对象是没用的。

垃圾回收器是用于回收堆区分配的对象。

垃圾回收器仅仅会回收3次的

  的内存。

垃圾回收器是虚拟机自己主动调用的。(堆区内存不够的情况下调用)



  可是能够通过System.gc()来强制执行垃圾回收器。

5:static静态块与对象块

寻找main方法--->载入类--->载入类的静态块代码(仅仅初始化一次)



--->载入类的静态方法和静态变量(仅仅初始化一次)---->对象块方法

--->对象的构造方法--->调用对象的方法--->运行对象的销毁方法。

//成绩类
class Score
{
int english;
int math;
int chinese;
Score(){ } Score(int english,int math,int chinese){
this.english = english;
this.math = math;
this.chinese = chinese;
}
} class Student{
int stuid;
String stuname;
String stusex;
//将成绩类做为学生类的一个属性。 Score score; public Student(Score score){
this.score = score;
} public int getTotalScore(){
return this.score.english +this.score.math +this.score.chinese;
} public void changeScore(Score score){
score.chinese = 0;
score.math = 0;
}
} public class Test_02{
public static void main(String args[]){
Score score_one = new Score(70,60,65);
//score_one.english = 70;
//score_one.math = 60;
//score_one.chinese = 65; Score score_two = new Score();
score_two.english = 11;
score_two.math = 12;
score_two.chinese = 13; Score score_three = new Score(45,46,47);
//score_three.english = 45;
//score_three.math = 46;
//score_three.chinese = 47; Student stu_one = new Student(score_three);
Student stu_two = new Student(score_two);
Student stu_three = new Student(score_one); /*
System.out.println(stu_one.getTotalScore());
System.out.println(stu_two.getTotalScore()); score_three.english = 70; stu_one.score.math = 23; System.out.println(stu_one.getTotalScore());
System.out.println(stu_two.getTotalScore()); */
System.out.println(stu_one.getTotalScore());//138 stu_one.changeScore(score_two); System.out.println(stu_one.getTotalScore());//138 stu_one.changeScore(score_three); System.out.println(stu_one.getTotalScore());//45 System.out.println(stu_two.getTotalScore());
}
}
public class Test_03
{
int id;
final static int MAX = 20; public static void main(String args[]){
//Test_03 test = new Test_03();
//System.out.println(test.MAX);
System.out.println(Test_03.MAX); }
}
class Person
{
int personid;
String personname; public Person(){
System.out.println("对象的构造方法");
this.personid = 1;
this.personname = "中国人";
} public void method(){
System.out.println("运行方法");
} public void finalize(){
System.out.println("对象被销毁了");
this.personid = 0;
this.personname = null;
}
}
public class Test_04
{
public static void main(String args[]){
Two(); System.gc();
} public static void Two(){
//创建对象
Person person = new Person(); //用对象
person.method();
} }
public class Test_05
{
//载入类时。最早运行的一块初始化内容。 static{
System.out.println("静态块");
} //载入类时,静态方法与静态变量都已经放到内存的静态区域中了。 public static void staticMethod(){
System.out.println("static方法");
} //对象块的内容,在对象初始化之前运行的内容
{
System.out.println("对象块方法");
}
//对象的构造方法
public Test_05(){
System.out.println("构造方法");
} public void objectMethod(){
System.out.println("对象方法");
} public static void main(String args[]){
Test_05.staticMethod(); Test_05 test = null;
test = new Test_05();
test.objectMethod(); Test_05 test2 = null;
test2 = new Test_05();
test2.objectMethod();
}
}
class Two
{
static{
System.out.println("Two的静态块");
}
}

J2SE基础:2.对象的创建与使用的更多相关文章

  1. [ Java学习基础 ] Java对象的创建和销毁

    类实例化可生成对象,实例方法就是对象方法,实例变量就是对象属性.一个对象的生命周期包括三个阶段:创建.使用和销毁. 创建对象 创建对象包括两个步骤:声明和实例化. 声明 声明对象与声明普通变量没有区别 ...

  2. [C++基础]关于对象的创建及内存分配

    测试: #include <stdio.h>#include <QDebug> class KPoint{public: KPoint(int x, int y){ nx = ...

  3. Java基础(2)面向对象和封装,对象的创建和使用、java对象的内存图

    1 类和对象 类:是一类事物的描述,抽象的.猫 对象:是一类事物的实例,具体的.某只猫 2 类的定义 成员变量和成员方法 //定义一个学生类 public class Student { //成员变量 ...

  4. J2SE基础题

    J2SE基础 八种基本数据类型的大小,以及他们的封装类.(有的也说是9中基本数据类型,包括了void) 基本类型 大小(字节) 默认值 封装类 byte 1 (byte)0 Byte short 2 ...

  5. JavaScript 基础回顾——对象

    JavaScript是基于对象的解释性语言,全部数据都是对象.在 JavaScript 中并没有 class 的概念,但是可以通过对象和类的模拟来实现面向对象编程. 1.对象 在JavaScript中 ...

  6. 图解JAVA对象的创建过程

    前面几篇博文分别介绍了JAVA的Class文件格式.JVM的类加载机制和JVM的内存模型,这里就索性把java对象的创建过程一并说完,这样java对象的整个创建过程就基本上说明白了(当然你要有基础才能 ...

  7. python基础——获取对象信息

    python基础——获取对象信息 当我们拿到一个对象的引用时,如何知道这个对象是什么类型.有哪些方法呢? 使用type() 首先,我们来判断对象类型,使用type()函数: 基本类型都可以用type( ...

  8. SQL Server 2008空间数据应用系列四:基础空间对象与函数应用

    原文:SQL Server 2008空间数据应用系列四:基础空间对象与函数应用 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2008 R2调测. ...

  9. VBS基础篇 - 对象(1) - Class对象

    VBS基础篇 - 对象(1) - Class对象   相信对JAVA有一定了解的朋友一定对类这个名词不陌生,但是大家可能没有想过在VBS中使用Class类吧,其实Class类在自动化测试中是相当常用的 ...

随机推荐

  1. spark 从RDD createDataFrame 的坑

    Scala: import org.apache.spark.ml.linalg.Vectors val data = Seq( (7, Vectors.dense(0.0, 0.0, 18.0, 1 ...

  2. zzulioj--1824--BOOM(模拟水)

    1824: BOOM Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 25  Solved: 5 SubmitStatusWeb Board Descr ...

  3. Windows下使用python绘制caffe中.prototxt网络结构数据可视化

    准备工具: 1. 已编译好的pycaffe 2. Anaconda(python2.7) 3. graphviz 4. pydot  1. graphviz安装 graphviz是贝尔实验室开发的一个 ...

  4. Java类和对象4

    编写Java应用程序.首先,定义一个Print类,它有一个方法void output(intx),如果x的值是1,在控制台打印出大写的英文字母表:如果x的值是2,在控制台打印出小写的英文字母表.其次, ...

  5. 在cncc的最后几天的笔记

    数据库范式:http://blog.csdn.net/fg2006/article/details/6936439 数据库事务隔离级别:http://blog.csdn.net/fg2006/arti ...

  6. 安装vue时使用npm install 报错

    npm ERR! Darwin 14.3.0 npm ERR! argv "/usr/local/Cellar/node/6.4.0/bin/node" "/usr/lo ...

  7. 不同框架实现的todomvc

    http://todomvc.com/ http://hao.jobbole.com/

  8. easyui-combobox实现取值范围的联动

    需求:需要用两个combobox来输入一个年月的范围,下拉框的内容从服务器获取.需要实现选中前者后,后者的下拉框中不能显示比前者数值小的:选中后者后,前者的下拉框内容不能显示比后者数值大的 有两个co ...

  9. 学习参考《Python基础教程(第3版)》中文PDF+英文PDF+源代码

    python基础教程ed3: 基础知识 列表和元组 字符串 字典 流程控制 抽象(参数 作用域 递归) 异常 魔术方法/特性/迭代器 模块/标准库 文件 GUI DB 网络编程 测试 扩展python ...

  10. 【SRM 716 DIV 1 A】 ConstructLCS

    Problem Statement A string S is a subsequence of a string T if we can obtain S from T by erasing som ...