2024年大数据最新初识面向对象上(2),2024年最新硬核

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

}

}



> 
> 类中包含的内容称为类的成员。属性主要是用来描述类的,称之为类的成员属性或者类成员变量。方法主要说明类  
>  具有哪些功能,称为类的成员方法。
> 
> 
> 


## 二、对象



> 
> 对象:对象是类的一个实例(对象不是找个女朋友),有状态和行为。例如,一条狗是一个对象,它的状态有:颜色、名字、品种;行为有:摇尾巴、叫、吃等。
> 
> 
> 


### 1.类的实例化


![在这里插入图片描述](https://img-blog.csdnimg.cn/723dcb4de3ec4246bef7e126ecf04ee7.png)  
 定义了一个类,就相当于在计算机中定义了一种新的类型,它是对对象的抽象。  
 用类类型创建对象的过程,成为类的实例化,在java中采用new关键字,实例化对象.



public class Test {
public static void main(String[] args) {
Dog dog = new Dog();//通过new实例化对象
dog.name = “旺财”;
dog.age = 18;
dog.bark();
dog.eat();
}
}


![在这里插入图片描述](https://img-blog.csdnimg.cn/b716c52e0fbf4aa19c3ddb287be03d1c.png)


### 2.类和对象的关系


1.类是一个模型,用来对一个实体进行描述,限制。  
 2.类是一种自定义类型,可以用来定义变量。  
 3.一个类可以实例化多个对象,类不占空间,只有实例化的对象才占真正的空间。  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/501d3d7c3dd241f4af45be7e371765ed.png)


### 三、this


### 1.this存在的意义



class Circle {
public int x;
public int y;
public int r;
public void setCircle(int a1,int a2,int a3) {
x = a1;
y = a2;
r = a3;
}
public void printCircle() {
System.out.println(x+" “+y+” "+r);
}
}
public static void main(String[] args) {
Circle circle = new Circle();
circle.setCircle(1,2,3);
circle.printCircle();
}


这样实例化一个对象,赋值,打印都没什么问题.  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/08b53dc8e4cc4a1594389bba18736a36.png)  
 但是我们在类中的set方法形参给的太抽象了,我们给的具体一点看一下



public void setCircle(int x,int y,int r) {
x = x;
y = y;
r = r;
}


![在这里插入图片描述](https://img-blog.csdnimg.cn/059deabd589d42e0934c151beafa9518.png)  
 为啥?不是已经进行赋值了吗,怎么会打印出来0  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/58430a39c5234b748410f4c08487370d.png)


### 2.this的引入


this指向当前对象,在成员方法中调用成员变量都是运用的this去访问。



public void setCircle(int x,int y,int r) {
this.x = x;
this.y = y;
this.r = r;
}
public void printCircle() {
System.out.println(this.x+" “+this.y+” "+this.r);
}


this引用的是调用成员方法的对象.



public static void main(String[] args) {
Circle circle = new Circle();
circle.setCircle(1,2,3);
circle.printCircle();
}


![在这里插入图片描述](https://img-blog.csdnimg.cn/04f05f1b019c4f06978c8afb0537c7d4.png)



> 
> 1.this的类型,那个对象调用就是那个对象的引用类型  
>  2.this只能在成员方法中使用  
>  3.this只能引用当前对象,不能在引用其他对象  
>  4.this是成员方法第一个参数,编译器会自动传递,编译器会将对象的引用传递给该成员方法,this负责接收.
> 
> 
> 


![在这里插入图片描述](https://img-blog.csdnimg.cn/60c483ea0d6a43baa36b708d53696ccc.png)


## 四、构造方法


### 1.初始化对象



public static void main(String[] args) {
int count;
System.out.println(count);
}



public static void main(String[] args) {
Dog dog = new Dog();
dog.eat();
}


下面两段代码能否通过编译?  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/9e253478df28452e9264e055deef9ad3.png)  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/41d2b2349a404284928b54981f09943b.png)



> 
> 1.为什么局部变量必须初始化才能使用,而对象可以不初始化?  
>  2.对象赋值有没有简单的方法?
> 
> 
> 


### 2.构造方法



> 
> 每个类都有构造方法。如果没有显式地为类定义构造方法,Java 编译器将会为该类提供一个默认构造方法。  
>  在创建一个对象的时候,至少要调用一个构造方法。构造方法的名称必须与类同名,一个类可以有多个构造方法。
> 
> 
> 



class Dog {
public String name;
public int age;

//无参的构造方法
public Dog(){
    
}
//带有两个参数的构造方法
public Dog(String name,int age) {
    this.name = name;
    this.age = age;
}

}


这里证明:构造方法也可以重载.  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/cda7f7e31d464609bb8f683d39f844be.png)



class Circle {
public int x;
public int y;
public int r;

public Circle(int x,int y,int r) {
    this.x = x;
    this.y = y;
    this.r = r;
}

}
public static void main(String[] args) {
Circle circle = new Circle();
}


![在这里插入图片描述](https://img-blog.csdnimg.cn/7e754816819d411091eb774c675382f2.png)  
 这里报错了,因为我们自己写了一个带参数的构造方法,所以系统不在自己生成构造方法.


**this的自我调用**



class Circle {
public int x;
public int y;
public int r;

public Circle() {
    this(3,2,1);
}

public Circle(int x,int y,int r) {
    this.x = x;
    this.y = y;
    this.r = r;
}
public void printCircle(Circle this) {
    System.out.println(this.x+" "+this.y+" "+this.r);
}

}
public static void main(String[] args) {
Circle circle = new Circle();
circle.printCircle();
}



> 


![img](https://img-blog.csdnimg.cn/img_convert/d452f872c3cd656e46202c33b3e5b8a9.png)
![img](https://img-blog.csdnimg.cn/img_convert/0f892eb2662b1d94915ba4ce4536303f.png)
![img](https://img-blog.csdnimg.cn/img_convert/008a947a488d02e825541283a40f1d38.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

18824696)]
[外链图片转存中...(img-ttvmjN4C-1715618824696)]
[外链图片转存中...(img-wzuL1Wfx-1715618824696)]

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

  • 16
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值