Results 1 to 6 of 6

Thread: Problem with abstract class and interface

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Problem with abstract class and interface

    Hello,
    I have a question for you guys, I am very new to java programming language. I wonder what are the abstract classes and interfaces. I'm reading tutorials I do not understand the concept. If you can help with these then it would be great. One more question can they both be used in the same class and then implemented by the other classes. Thank in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Problem with abstract class and interface

    Hello,
    I think both the concepts are very easy, and I think the abstract classes are more strong and very important to use in the classes because they are fast in execution, I would like to explain you those here
    General explanation of the abstract class
    - It Can not be instantiated
    - It is used to define common methods for derived classes
    - It can be used to treat different objects (children) by their common foundation
    Hope this information will help you.

  3. #3
    Join Date
    Nov 2009
    Posts
    518

    Re: Problem with abstract class and interface

    Hello,
    The above explained is correct and I would like to explain interface here.
    Interface
    - Used to define methods, constants (behavior), a bit like a prototype method (no implementation)
    - An object can implement multiple interfaces (as opposed to the inheritance can not inherit only one object) and must implement the methods of the interface (or interfaces)
    - Can be used to "see" an object through the interface
    I think both the abstract class and the interface are the key features of the java programming language, which make the language so popular and easy to use.

  4. #4
    Join Date
    Nov 2009
    Posts
    343

    Re: Problem with abstract class and interface

    Hello,
    See the below example, it will surely help you.
    Code:
    class stu implements Similar 
    {
        
        int n;
        
        Public int getNote(){
            return n;
        }
        
        Public int compareTo(O stu)
        {
            if( n == o.getNote() )
                return 0 ;
            else if( n> o.getNote() )
                return 1 ;
            else
                    return -1;
        }
        
    }
     
    class Employee implements Similar <Employee>
    {
        
        int w;
        
        Public int getsal(){
            return w;
        }
        
        Public int compareTo(Employee No.)
        {
            if( sal == o.getsal() )
                return 0 ;
            else if( sal> o.getsal() )
                return 1 ;
            else
                    return -1;
        }
        
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Problem with abstract class and interface

    Hello,
    Here is am sample code, see if this can help you

    Code:
    abstract class Person
    {
        String nm;
    
        String firstName;
    
        Public String getName()
        {
            return nm;
        }
     
        Public String getPrenom()
        {
            return surnm;
        }
     
        Public abstract String getDescription();
     
    }
     
    class Employee extends Person
    {
        int w;
    
        Public String getDescription()
        {
            return getName() + " " + GetPrenom() + "To pay for" + Salary;
        }
     
    }
     
    class Student extends Person
    {
        int n;
    
        Public String getDescription()
        {
            return getName() + " " + GetPrenom() + "To pay for" + n;
        }
     
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Problem with abstract class and interface

    Hello,
    It can also be detached completely from the reference implementation for the objects it references a type that knows nothing of his way to work and suddenly this way is left open for classes that implement the interface. Very powerful in all cases. I recommend you to read some basic of the java programming language, that it the core java. If you have any more queries then do post back and we will try to answer you with the same.

Similar Threads

  1. Abstract class method overloading problem
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 10:18 AM
  2. Difference among concrete class and abstract class
    By Roxy_jacob in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 01:22 PM
  3. Abstract class in Java
    By SoftWore in forum Software Development
    Replies: 3
    Last Post: 07-11-2009, 01:58 PM
  4. Abstract class and Interface in .net
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 04-05-2009, 06:07 PM
  5. Replies: 4
    Last Post: 02-03-2009, 08:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,993,309.62015 seconds with 16 queries