• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

some problems with terminology...

 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am referring to desborough's notes and have problems understanding some of his terms....
1.)"Private method calls are statically bound ... a method will call the private method in the class where it is defined .. even if the calling method is inherited by a derived class and the derived class defines a method with the same signature as the private method."
what does statical binding mean?
2.)"A static method can be overriden by a static method but does not dynamically bind (therefore static methods can't be abstract)"
come again?!?
3.)"Interfaces automatically attach 'public static final' to field and class members (thus making them top-level nested rather than member inner classes)."
i disagree with this one. . the interface can only have two modifiers - the public and the default.i think that the public modifier is added "automatically" when the interface is declared coderanch. not when it is default.... please confirm. it is my request that you be sure of your answer to this one and it would be very helpful if you could back this with some literature snippet....
thanx.....
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)Private methods are never inherited hence they can never be overriden. Hence private method calls are bound at compile-time & not at run-time.
eg:
class Base
{
private void foo()
{
}
public static void main(String[] args)
{
Base b = new Derived();
b.foo();
}
class Derived extends Base
{
private void foo()
{}
}
In the above example, foo() of Base will be called even though b references Derived object. This is what is mean by "private methods are statically-bound".
2)Same explanation goes for static methods (in the above example replace private with static). Static methods and variables are bound at compile-time. A good example of this would be:
AnObject o = null;
o.anyStaticMethod();
The above code will NOT throw a null-pointer exception since static methods are bound at compile-time.
3)Interface can be declared public or default. However irrespective of whether an interface is public or not, the fields declared in an interface are always public static & final by default, whether you explicitly declare them or not. Similarly methods of any interface are always public and abstract by default.
Hope this clears the confusion!
Junaid Bhatra
Sun Certified Programmer for the Java 2 Platform
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx got it... i was just getting lost in the terminology...
can you just explain why static methods can't be abstract as it is written in the notes?
thanx
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static methods should not be abstract because it defeats their purpose in being either. if it is static, it pertains to a class i.e. it is a class method. if it is abstract it is meant to be implemented elsewhere in another subclass, maybe. so if u make it static and abstract, an instance of that class will never be able to access it and implement it.
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice reply....but i'm not thoroughly convinced...
s'ppse
abstract class a{
abstract static void method();
}
class a1 extends a{
static void method(){
System.out.println("What the heck!");
}
public static void main(String args[]){
new a1().method();
}
}
as you see the abstract class may have been declared static just to make it possible to implement the class as static! i mean, a static method can only override a static method, right?
btw, the code doesn't compile... it gives the error:
a1.java:2: illegal combination of modifiers: abstract and static
abstract static void method();
i'm just presenting a possible need for it... pls. correct me coz i know i am wrong somewhere.....
 
Sweekriti D
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
firslty, outer classes/interfaces cannot be declared static.
secondly, methods and classes are different, i.e. even if u can have an abstract static inner class u cannot have abstract static methods. u dont ever need to give an implementation of a class as u might to a method. no problems with subclassing an abstract static class, but an abstract method is meant to be implemented somewhere - how can u justify different individual implementations of the abstract method if it is static?

[This message has been edited by Sweekriti D (edited January 25, 2001).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to rain the parade, but the name 'Seekriti D' does not comply with the JavaRanch naming policy. Please choose one that meets the requirements.
Thank you!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
 
reply
    Bookmark Topic Watch Topic
  • New Topic