Is using 'extend' keyword the only way to create a SUB-CLASS?

//Let us say i have a superclass

class SuperClass {

//code here

}

//Now i create a sub-class of superclass

class SubClass extends SuperClass {

//code here

}

What about 'import' statement. Does it create a sub-class too? Kindly explain me in details. Thanks!

[314 byte] By [New-Drop@Java-Seaa] at [2007-11-26 13:53:29]
# 1
> What about 'import' statement. Does it create a> sub-class too? No it does not.The simple answer is that there is only one way and that is by using extends.Kaj
kajbja at 2007-7-8 1:31:37 > top of Java-index,Java Essentials,New To Java...
# 2

> What about 'import' statement. Does it create a sub-class too?

Huh? No.

"import" just allows you to 'shorthand' class names.

The "java.lang" package is imlicitly imported, otherwise you'd have to refer to the String class as java.lang.String - this has nothing to do with subclassing.

> Is using 'extend' keyword the only way to create a subclass?

No, there is a mechanism for creating anonymous subclasses.Thread foo = new Thread() {

run() {

// my code here

}

}

This creates an anonymous subclass of Thread, and creates an instance of this new subclass.

tschodta at 2007-7-8 1:31:37 > top of Java-index,Java Essentials,New To Java...
# 3

> Kindly explain me in details. Thanks!

"extends" declares a subclass or sub-interface. "implements" declares an implementation of an interface. All of these are subtyping.

"import" simply saves you some typing and keeps your code more readable by telling the compiler that when you write "Foo" you really mean "some.package.Foo."

jverda at 2007-7-8 1:31:37 > top of Java-index,Java Essentials,New To Java...
# 4
You know, the Java programming guide book, the Java tutorials, lots of good third-party books...they all tell you how Java works. You should try reading them.
paulcwa at 2007-7-8 1:31:37 > top of Java-index,Java Essentials,New To Java...