The difference between a Java class and an object

Source: Internet
Author: User
Tags define abstract

The difference between Java classes and objects is a cliché, and when you start learning Java, you begin to touch classes and objects, and today you can summarize the differences between them.

First of all, the difference between class and object is a word: object is the parent of all classes, and all class classes inherit object by default.

Classes in Java are an abstraction of the properties and behaviors of a class of "things", such as human beings that can be defined as a person class:

public class Personal {public int age;//age public String name;//name public int hight;//height public int weight;//weight Public person () { }public person (int age,string name,int hight,int weight) {this.age = Age;this.name = Name;this.hight = Hight;this.weight = Weight;} public void Dosth () {//dosomething}}
object is the instantiation of a class, that is, a specific individual, such as "Moro" I am a specific object of the person class, I have their own specific age name height and weight.

In simple terms, the differences between classes and objects are as follows:

1, a class is an abstract concept that does not exist in real time/space, and classes simply define abstract properties and behaviors for all objects. It is like the "person" class, which can contain many individuals, but it does not exist in the real world itself.
2, the object is a specific class. It's a real thing.
3, a class is a static concept, and the class itself does not carry any data. When no objects are created for a class, the class itself does not exist in memory space.
4, the object is a dynamic concept. Each object has its own unique properties and behaviors that are distinct from other objects. The properties of an object can change with its own behavior

Finally, let's look at the differences between class and object invocation methods:

public class Classandobject {//static method public static void Statictest () {System.out.println ("This is a static method! ");} Dynamic method public void Dynamictest () {System.out.println ("This is a dynamic method! ");} public static void Main (string[] args) {classandobject.statictest ();//correct classandobject t = new Classandobject (); T.dynamictest ();//The non-static method must use the object. method, because it does not exist before the object is created, and must depend on the creation of the object to be used. T.statictest (); Warning shown here: the static method Statictest () from the type classandobject should is accessed in a static        way//static methods before the object is created After the existence, its use does not depend on the creation of objects, you can directly use the "class. Static method"

Welcome to follow the public number (Xingzhemoluo), common communication programming experience, scan the following QR code can be;

                               

The difference between a Java class and an object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.