2024年5月20号【Java again for oop】

Core: Compiler Rules for Class Construction

what we will learn today is compiler rules for class construction

In the last video, we saw how objects are constructed from the inside out in Java. 

And the way this happens is really through compiler rules. 

We're gonna talk about what those compiler rules are and how those compiler rules 

work, in order to ensure, again, that the object is created from the inside out.

But you've said at the end but wait, I don't remember extending object.Where did we do this? This introduces our first rule associated with a compiler. So let's revisit where the compiler plays a role in our process.

So what is a Java compiler doing and what are these rules?

Core: Variable Initialization in a Class Hierarchy

In the past couple of videos, we've been starting to look at how class creation, or 

object creation happens in Java.

specifically how does inheritance apply to object creation.

Now these compiler rules are what the compiler does when it looks at your code. 

Now the reason we want to know about these rules, 

is because it's going to help us trace our code. 

In fact, we're going to see an error in our code here in just a little bit, 

which comes about because of these rules.

If you start to recognize that I'm not allowed to say this.name, you're right. 

That's a private variable in the person class. 

I'm not allowed to direct the access of that in the student class, 

I'd have to use a getter or a setter to do so.

But I don't have a getter or a setter. Is there a way for me to do this? 

Can I initialize name without having the public getter setter? 

The answer is yes. 

All I have to do is change this now to call the superclass constructor 

that takes an argument, which is gonna initialize to be named.

Concept Challenge: Inheritance Constructors 1:

Concept Challenge: Inheritance Constructors 2

Core: Method Overriding

So goal here today is where the create methods are override from superclass methods and will the contrast overloading from method overriding.

So we wanna have common code in one pairing class. We do this if we don't override a method. So if a method just exists in the superclass we get back common code. But if we want our subclasses to behave differently all we have to do is override a method and now we get that different behavior.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值