How to not extend the Object class in Java?

Mr. Stackoverflow :

By default, every class in Java extends the Object class. (So single inheritance always occurs)

Is there any class that does not extend Object class? (eg. int might be an instance of the class int but not an object)

Can we somehow create our own class that doesn't extend Object? Maybe by modifying javac's final code to not extend Object class and maybe create our own class to surpass things that the constructor of the object class does at minimum to avoid abnormal behavior?

Andronicus :

int is a primitive, hence we cannot say it extends anything.

When it comes to your question:

Is there any class that does not extend Object class?

You have answered it literally line above:

every class in Java extends the Object class

P.S.: We cannot say, that there is a dual inheritance, because a class extends Object and some other class, because that "other class" also extends Object. In fact, a class is a subtype of all its supertypes, for example:

HashMap m = new LinkedHashMap();
AbstractMap m = new LinkedHashMap();
Object m = new LinkedHashMap();

Type parameters omitted for brevity.

Edit: referencing the discussion about what is an object and what is not, JLS §4.3.1 gives the answer:

An object is a class instance or an array.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=316988&siteId=1