Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Problem with abstract class and interface

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 08-03-2010
Member
 
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.

Reply With Quote
  #2  
Old 08-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 08-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 08-03-2010
Member
 
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;
    }
    
}
Reply With Quote
  #5  
Old 08-03-2010
Member
 
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;
    }
 
}
Reply With Quote
  #6  
Old 08-03-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem with abstract class and interface"
Thread Thread Starter Forum Replies Last Post
Abstract class method overloading problem ISAIAH Software Development 5 16-01-2010 10:18 AM
Difference among concrete class and abstract class Roxy_jacob Software Development 4 07-12-2009 01:22 PM
Abstract class in Java SoftWore Software Development 3 07-11-2009 01:58 PM
Abstract class and Interface in .net RogerFielden Software Development 3 04-05-2009 06:07 PM
What's the difference between an interface and an abstract class in JAVA? Vaibhav S Software Development 4 02-03-2009 08:46 PM


All times are GMT +5.5. The time now is 03:01 PM.