03. Java Classes

本文介绍了面向对象编程的基本概念,包括类的定义、实例变量与局部变量的区别、构造函数的使用、继承的概念及super关键字的应用等核心知识点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

What is a Class?

A class is a templete definition (blueprint)

It defines the data contained in objects that are members of a class

It defines the methods (operations) that can be performed on those data


Constructors

To instantiate a new instance (object), invoke a constructor of the class using the new operator

- e.g. AddressBookEntry abe = new AddressBookEntry();

Must have the same name as the class itself

- File name, Public Class name, and Constructor Name should be the same

The Default Constructor

- If no constructors are explicitly defined in class, a public no-arg constructor with an empty body is implicitly defined in the class


Accessing via Reference Variables

Newly created instances (objects) are allocated in the memory

- They can be accessed via reference variables

Instance variables are "field" in an object

- e.g. kevin.firstName = "Kevin";


Instance variables vs. Local variables

Instance variables are fields that are unique to each instance of a class

- e.g. terry's first name is different from jeff's first name

Local variables are within methods

- Visible only to the method it is declared

- Not accessible from the rest of the class


Inheritance

A class (subclass) can extend a class (superclass)

- Subclass inherits accessible fields and methods from the superclass

- Subclass may add more fields

- Subclass may add more methods

- Subclass may override some methods of Superclass


Super keyword

Can be used to call superclass method

- To refer to print() method inherited from SuperClass (AddressBookEntry) in SubClass, SubClass (MyEntry) must use a qualified name using super keyword


Integrated Development Environment

- Source-code, syntax-directed editor

- Incremental complier

- Repository-based environment for code

- Project-based development

- Integrated debugging

- Support for team development

- Tools to facilitate specific programming models (Applets, Servlets, EJBs, Stored Procedures, XML, …)


Sample Final Exam Question

What is object-oriented programming?

Write programs using objects

- Objects that specify their (internal) data

- Objects that specify the methods by which you can manipulate their data

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值