finding java difficult  
Author Message
x343181





PostPosted: 2006-3-4 3:39:00 Top

java-programmer, finding java difficult I know Visual Basic and few other commands in Oracle but I am having
trouble learning high level Java. Should I just read over and worry
about it later? I understand Arrays and If statements but found for
example, " overiding and hiding methods" difficult. It states a
superclass overides a superclass. I am confused!

here is "overiding and hiding methods" from the sun.com site;

An instance method in a subclass with the same signature and return
type as an instance method in the superclass overrides the superclass's
method. (Remember that a method's signature is its name and the number
and the type of its arguments.) You can also override a method with the
same signature that returns a subclass of the object returned by the
original method. This facility (introduced in 5.0) is called covariant
return type and you can see an example in Annotations (in the Learning
the Java Language trail).

 
James McGill





PostPosted: 2006-3-4 3:59:00 Top

java-programmer >> finding java difficult On Fri, 2006-03-03 at 11:39 -0800, email***@***.com wrote:
> I understand Arrays and If statements but found for
> example, " overiding and hiding methods" difficult. It states a
> superclass overides a superclass. I am confused!

You understand basic data storage and procedural control structures, but
you have no exposure to Object Oriented design and programming.

There's a whole lot to learn, and several ways to go about it.

One place to start from the Sun site is here:

http://java.sun.com/docs/books/tutorial/java/concepts/

I think you may have already gotten past that, but the example you gave
is not in the most introductory language. There are a few basic ideas
that you need to solidly understand, before you should get into the
specifics of inheritance and method overloading, and that sort of thing.

Google for Bruce Eckel and read the (free) PDF version of his book.

Consider taking a semester-long college course in java programming.


 
opalpa@gmail.com opalinski from opalpaweb





PostPosted: 2006-3-4 4:08:00 Top

java-programmer >> finding java difficult > It states a superclass overides a superclass

That's not what I read the statement to say. "An instance method in a
subclass " ... "overrides the superclass's method" .

The words omitted with elipses qualify the first part.

Opalinski
email***@***.com
http://www.geocities.com/opalpaweb/

 
 
jagonzal





PostPosted: 2006-3-4 4:10:00 Top

java-programmer >> finding java difficult email***@***.com wrote:
> I know Visual Basic and few other commands in Oracle but I am having
> trouble learning high level Java. Should I just read over and worry
> about it later? I understand Arrays and If statements but found for
> example, " overiding and hiding methods" difficult. It states a
> superclass overides a superclass. I am confused!
>
> here is "overiding and hiding methods" from the sun.com site;
>

Seems like you need to pick up some Object-Oriented basic concepts.

 
 
Matt Humphrey





PostPosted: 2006-3-4 4:13:00 Top

java-programmer >> finding java difficult
<email***@***.com> wrote in message
news:email***@***.com...
>I know Visual Basic and few other commands in Oracle but I am having
> trouble learning high level Java. Should I just read over and worry
> about it later? I understand Arrays and If statements but found for
> example, " overiding and hiding methods" difficult. It states a
> superclass overides a superclass. I am confused!
>
> here is "overiding and hiding methods" from the sun.com site;
>
> An instance method in a subclass with the same signature and return
> type as an instance method in the superclass overrides the superclass's
> method. (Remember that a method's signature is its name and the number
> and the type of its arguments.)

That passage is referring to the following case:

class A {
void doFirst (int p) { }
void doSecond (int p) { }
}

class B extends A {
void doSecond (String p) { }
void doSecond (int p, int q) { }
void doSecond (int p) { }
void doThird (int p) { }
}

B b = new B ();
b.doFirst (0); // Code from class A is executed
b.doSecond (0); // Code from class B is executed -- this overrides doSecond
(int p) from class A
b.doSecond (0,0); // Code from class B is executed
b.doSecond (""); // Code from class B is executed
b.doThird (0); // Code from class B is executed

The other methods of B do not override because they do not have the same
signature--either the name or parameter types are different

-or-

A b = new B (); // All Bs are also As
b.doFirst (0); // Code from class A is executed
b.doSecond (0); // Code from class B is executed -- this overrides doSecond
(int p) from class A

No methods of B are accessible here because the compile time type of the
variable is A. The class of the object, however is B. This explains why
class B's version of the method is called even though the variable is of
type A. The method is selected by the class of the receiver. You can
correctly cast b to a variable of type B as in

B aRealB = (B)b;

and now use the other B methods. If the object referred to by variable b
were not actually of class B (or a subclass) you would get a
ClassCastException here.

> You can also override a method with the
> same signature that returns a subclass of the object returned by the
> original method. This facility (introduced in 5.0) is called covariant
> return type and you can see an example in Annotations (in the Learning
> the Java Language trail).

In the past you could not have two methods with the same signature but
different return types, as in

class A {
int myMethod ();
}

class B extends A{
float myMethod ();
}

The above is still impossible, but the restriction has been relaxed in 5.0
so that the following is possible:

class A {
Number myMethod ();
}

class B extends A {
Double myMethod ();
}

The subclass may have a different return type provided that the return type
is a subclass of the superclass's method's return type. The Double return
type of class B's myMethod is a subclass of class A's myMethod's return
type Number.

Cheers,
Matt Humphrey email***@***.com http://www.iviz.com/


 
 
wilberX





PostPosted: 2006-3-4 4:19:00 Top

java-programmer >> finding java difficult Overriding methods can be confusing at first, but it provides a useful
solution to object oriented problems. One useful feature of object
oriented programming is being able to re-use the same code to get
different results. Lets say you have a superclass and two subclasses
that both inherit from this superclass. And lets say that you want to
use a method in the superclass to get different results for each
subclass. In procedural programming, you would need to write a
different method for each result you want. The helpful thing about
object oriented is you can "overide" this method in each subclass. All
this overiding means is that you will write your method in your
superclass, and then overide it by using the same method in a subclass.
This overidden method in each sublass can be tailored to do different
things than the original method that your are overiding from the
superclass. Its that easy! It might seem abnormal, but go ahead and
try it. Remember, the compiling errors are usually specific and will
tell you what and where you went wrong. Also try looking up info about
abstract methods and classes. This abstract concept might clear some
things up for you as well. OOP FTW!


email***@***.com wrote:
> I know Visual Basic and few other commands in Oracle but I am having
> trouble learning high level Java. Should I just read over and worry
> about it later? I understand Arrays and If statements but found for
> example, " overiding and hiding methods" difficult. It states a
> superclass overides a superclass. I am confused!
>
> here is "overiding and hiding methods" from the sun.com site;
>
> An instance method in a subclass with the same signature and return
> type as an instance method in the superclass overrides the superclass's
> method. (Remember that a method's signature is its name and the number
> and the type of its arguments.) You can also override a method with the
> same signature that returns a subclass of the object returned by the
> original method. This facility (introduced in 5.0) is called covariant
> return type and you can see an example in Annotations (in the Learning
> the Java Language trail).

 
 
Roedy Green





PostPosted: 2006-3-4 7:04:00 Top

java-programmer >> finding java difficult On 3 Mar 2006 11:39:29 -0800, email***@***.com wrote, quoted or
indirectly quoted someone who said :

>It states a
>superclass overides a superclass. I am confused!

Brings back memories. Here are some entries in the Java glossary that
may explain this in more informal language.

http://mindprod.com/jgloss/override.html
http://mindprod.com/jgloss/gotchas.html#OVERRIDE
http://mindprod.com/jgloss/shadow.html
http://mindprod.com/jgloss/subclass.html
http://mindprod.com/jgloss/superclass.html
http://mindprod.com/jgloss/overload.html
http://mindprod.com/jgloss/static.html
http://mindprod.com/jgloss/instance.html
http://mindprod.com/jgloss/virtual.html

Also just go through the gotchas. The explain the tricky stuff like
ArrayStoreExceptions.
http://mindprod.com/jgloss/gotchas.html

It is not nearly as complicated as it first seems. Everything really
does behave the way you would expect.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.