Results 1 to 5 of 5

Thread: Abstract Methods [resolved]

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Abstract Methods [resolved]

    Abstract classes can contain final methods? This is what
    i just read somewhere and i think that the statement is
    inaccurate.

    They go on to say that Abstract Classes can contain
    bolth final methods and non-abstract methods.

    The latter i can see as being correct becuse it is implied that
    a method declared in an abstract class is abstract wether the
    abstract key word is specified or not.

    A final method cannot be overridden. An abstract method implies
    that somewhere down the line implementation will be provided
    for this method, so how can you have bolth?

  2. #2

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    This code generates an error. "unable to overide testMethod(java.lang.String) overridden method is static and final"

    so i guess this answers my question. But any thoughts on this
    matter would be much appreciated.

    Code:
     abstract class Message{
         final static void testMethod(String msg) {};     
      }
     public class Greeting extends Message{ 
        public static void main(String[] args){
           testMethod("Hello");      
        }
     static void testMethod(String msg){
           System.out.println(msg); 
        }
    }

  3. #3
    VirtuallyVB
    Guest
    An abstract house is a house that is incomplete.
    The walls may be complete, but if one component is incomplete, say the roof, then we only have an abstract house. We have to say that the entire house is not finished -- let's not use that word, let's say that the entire house is not defined. The roof has not yet been implemented. I may put on a different type of roof than someone else.

    How's that analogy?

    If the house is finally completed....aah that doesn't work. Usually people can add extensions to rooms, inheriting the main design. Final may be like when you can't add any more rooms due to zoning/compiler rules.

    Anyway, you said you figured it out.

  4. #4

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I basically aswered the question "Can abstract classes can contain final methods?" I guess they can but i dont see how
    or why this is allowed. Answer me this.. if a method is defined within an abstract class, it is abstract wether the abstract key
    word is provide within the method signature or not. Right?

    So.... a final method with the keyword final implies that it is not able to be overriden. An abstract method implies
    that somewhere down the line implementation will be provided(somewhere down the line it will be overridden.)


    So i really dont see how you can have bolth. I do like your analogy though

  5. #5

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Just wanted to resolve this post. Abstract classes can contain
    "non-abstract" methods but if an abstract class contains one or more abstract methods then it must be declared abstract. A method cannot be declared bolth abstract and final


    Code:
        abstract class MyClass {
         
        public int computeSum (int i, int k){return i + k;} 
        
        // result is a complation error. 
        public abstract final int computeQuotent(int i, int k){return i / k;} 
    
       }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width