Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does 'extends Object' have a purpose or is it redundant?

Tags:

java

Following a tutorial on the internet regarding Soap development with Java, I found this link, with a rather unusual code for myself.

The code:

public class SoapService extends Object {      /** Creates new SoapService */     public SoapService() {     }  /** This is the SOAP exposes method */     public String sayGreeting(String name)     {         return "Hello "+name;     } } 

What's with the 'extends Object' syntax ? I've never encountered this kind of syntax (only on Generics).

Does this syntax has any purpose or is 'plain dumb' ?

like image 553
Andrei Ciobanu Avatar asked Feb 16 '10 17:02

Andrei Ciobanu


People also ask

What does extends Object mean?

extends Object> means you can pass an Object or a sub-class that extends Object class. ArrayList<? extends Number> numberList = new ArrayList<Number>(); //Number of subclass numberList = new ArrayList<Integer>(); //Integer extends Number numberList = new ArrayList<Float>(); // Float extends Number.

What does extends Object mean in Java?

The extends keyword extends a class (indicates that a class is inherited from another class). In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories: subclass (child) - the class that inherits from another class.

Is extends Object a bounded wildcard?

extends Object> is a bounded wildcard (an unknown that extends Object , whereas <E extends Object> is type bounded ( E requires a Parameterized type that extends Object ).

Does Object extend Object?

Object does in fact not have an extends clause (and because the Object class is primordial and has special treatment in the spec, there's no extends Object implicitly present). Additionally, you may observe that the value of Object.


2 Answers

Unless the Object class is not actually the java.lang.Object class (the tutorial does not include the imports, so it's hard to see), the extends Object is redundant.

like image 168
Thomas Lötzer Avatar answered Sep 26 '22 02:09

Thomas Lötzer


All objects in Java implicitly extend Object, so I'd say it's redundant.

like image 35
Erich Douglass Avatar answered Sep 24 '22 02:09

Erich Douglass