|
| |||||||||
| Tags: abstract class, class, function, interface, java, member variables, method, programming language |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 07: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 |