- Hands-On Automation Testing with Java for Beginners
- Rahul Shetty
- 197字
- 2021-07-23 16:26:32
Importance of classes and objects in Java
Objects are instances or references of a class. So we can call the methods and variables present in this class with the help of their objects. We cannot call methods and objects directly, we can only use them with the help of their objects. So first, we need to create objects for the class, and then we can call the method inside the main class.
Let's take a look at the previous example to explain this:
package coreJavaTraining;
public class Firstclass {
public void getData()
{
System.out.println(" I am in method");
}
public static void main(String[] args)
{
System.out.println("hi");
System.out.println("hello world");
}
}
Since the main block is already in the class, why do we need to create an object again for this class and call it?
The answer is that there is no way that the main block will come to know about the method outside it until and unless we create an object to call the method. There is an exception for that, which is the static variable, saying that the method is static. So, in general, accessing other methods is only possible with objects.
- Java多線程編程實戰指南:設計模式篇(第2版)
- Mastering OpenCV Android Application Programming
- 編程卓越之道(卷3):軟件工程化
- FFmpeg入門詳解:音視頻流媒體播放器原理及應用
- Linux網絡程序設計:基于龍芯平臺
- bbPress Complete
- Unity 2017 Mobile Game Development
- C和C++游戲趣味編程
- ServiceNow:Building Powerful Workflows
- 區塊鏈技術進階與實戰(第2版)
- Sails.js Essentials
- Python 3快速入門與實戰
- Python編程入門(第3版)
- Java Web 從入門到項目實踐(超值版)
- Swift從入門到精通 (移動開發叢書)