Results 1 to 7 of 7
Thread: abstract
- 03-08-2011, 07:06 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
- 03-08-2011, 07:10 AM #2
Member
- Join Date
- Mar 2011
- Location
- Pune, India
- Posts
- 5
- Rep Power
- 0
Abstract class can contain abstract methods, abstract property as well as other members (just like normal class).
Interface can only contain abstract methods, properties but we don’t need to put abstract and public keyword. All the methods and properties defined in Interface are by default public and abstract.
//Abstarct Class
public abstract class Vehicles
{
private int noOfWheel;
private string color;
public abstract string Engine
{
get;
set;
}
public abstract void Accelerator();
}
//Interface
public interface Vehicles
{
string Engine
{
get;
set;
}
void Accelerator();
}
- 03-08-2011, 08:56 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 03-08-2011, 09:33 AM #4
Member
- Join Date
- Mar 2011
- Location
- Pune, India
- Posts
- 5
- Rep Power
- 0
I am not that much senior to answer you but if you are asking then I will try,
An abstract method/property is a method that is declared without an implementation.
When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
Can you explain what is wrong in that code?
- 03-08-2011, 09:37 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Yes, but the term "abstract property"?
That makes no sense to me.
Surely that's just an abstract method? Since you can't have abstract attributes...
As for the code:
The bits in bold are all wrong.Java Code:public abstract [B]string [/B]Engine { [B] get; set; [/B]} public interface Vehicles { [B] string Engine { get; set; }[/B] void Accelerator(); }
- 03-08-2011, 09:56 AM #6
an other difference is when a class want to use an interface the class must be declared with the keyword implements and when the class want to use an abstract class the class must be declared with the keyword extends. in both cases the class must implement all abstract methods.
@vitthal: Real-world objects contain state and behavior, java objects contain fields and methods.Last edited by j2me64; 03-08-2011 at 10:00 AM.
- 03-08-2011, 10:05 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Not abstract and doesn't override abstract method keyReleased
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 02-19-2011, 04:32 AM -
SkeletonMidlet is not abstract and does not override abstract method
By just_in_deed in forum CLDC and MIDPReplies: 3Last Post: 08-13-2010, 04:57 AM -
...is not abstract and does not override abstract method...
By Addez in forum New To JavaReplies: 3Last Post: 09-16-2009, 09:27 PM -
GameImpl is not abstract and does not override abstract method
By Macca07 in forum New To JavaReplies: 2Last Post: 11-21-2008, 12:20 AM -
Error! "filename" is not abstract and does not override abstract method...
By hasani6leap in forum New To JavaReplies: 6Last Post: 10-27-2008, 12:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks