Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines    

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > JAVA Technologies
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 16-02-06, 06:39 AM   #1 (permalink)
Junior Member
 
Join Date: Feb 2006
Location:
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3 swathi4_9 has disabled reputation


hi friends,


i had one doubt regarding abstract classes.any abstract class may have concretemethods without any abstract methods.so even it is having only concrete methods why we can't create an object of abstract class?


reply soon


bye


swathi
swathi4_9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 16-02-06, 08:08 AM   #2 (permalink)
Senior Member
 
meenakshisekar's Avatar
 
Join Date: Feb 2006
Location: India
Posts: 546
Thanks: 7
Thanked 7 Times in 5 Posts
Thanks: 7
Thanked 7 Times in 5 Posts
Rep Power: 8 meenakshisekar has disabled reputation


hi swathi


when u r creating a abstract class it means that u can't create obj for that.hence u can't create obj for concrete methods too.


if u need to access concrete methods of abstract class


extend abstract class in another class create obj for sub class access concrete methods thro subclass obj.


__________________
try try try till u succeed
meenakshi
meenakshisekar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 16-02-06, 12:23 PM   #3 (permalink)
Moderator
 
Join Date: Feb 2006
Posts: 1,413
Thanks: 0
Thanked 9 Times in 8 Posts
Thanks: 0
Thanked 9 Times in 8 Posts
Rep Power: 18 sowmya571 has disabled reputation
hello



Abstract class must be extended/subclassed
(to be useful). It serves as a template.
A class that is abstract may not be instantiated
(ie, you may not call its constructor),
abstract class may contain static data.
Any class with an abstract method is automatically
abstract itself, and must be declared as
such.


A class may be declared abstract even if
it has no abstract methods. This prevents
it from being instantiated.



abstract class must contain atleast one abstract method rest might be concrete /abstract . Abstract
class must have subclasses

so as meena said u need to extend abstract class in another class create obj [/b]for sub class [/b]access concrete methods thro subclass obj.



[/b]
__________________
http://livetolead.blogspot.com/
all the best
Arise Awake N Stop Not Until Ur Goal Is Reached!
sowmya571 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 16-02-06, 12:24 PM   #4 (permalink)
Moderator
 
Join Date: Feb 2006
Posts: 1,413
Thanks: 0
Thanked 9 Times in 8 Posts
Thanks: 0
Thanked 9 Times in 8 Posts
Rep Power: 18 sowmya571 has disabled reputation
hello



raed this

A class is called abstract if it
has at least one abstract (not implemented) method. The keyword abstract has to
be placed in the definition of the method(s) and the class
itself. For example, the following class has three concrete and one abstract
method:



Listing
1: Abstract class Person



public
abstract class Person {


public void
changeAddress(String address){

System.out.println("New address is"
+
address);
}


private void
giveDayOff(){

System.out.println("Class Person: Adding a day
off");
}

public void promote(int
percent){

System.out.println("Class Person: Promoting a


worker...");

giveDayOff();

//calling an abstract method

raiseSalary(percent);
}


public abstract boolean raiseSalary

(int percent);
}






Abstract classes cannot be
instantiated, but they allow you to create superclasses, which implement some of
the functionality, while leaving one or more methods to be implemented in
subclasses.

The class Person can contain dozens of concrete
methods that are the same for every person like changeAddress and giveDayOff, but since the process of
raising salary is different for employees and consultants, the
method raiseSalary
should remain abstract. Please note
that even though this method is abstract, it could be called
in an abstract class because by the time the concrete class will be
instantiated, the method will be already implemented. Since we have two type of
workers, let’s create subclasses Employee and Consultant, and implemented the method
raiseSalary based on different
rules.

Listing
2: Class Employee, version 1




public class
Employee extends Person{
public boolean
raiseSalary(int percent){

if (percent<10){

// The code to increase

// the salary goes here

System.out.println(
"Class
Employee:Increasing salary by "+

percent + "%");

return true;

} else{

System.out.println(

"Our limit is 10%, sorry...");
return
false;

}
}
}





Listing
3: Class Consultant, version 1




public class
Consultant extends Person{

public boolean raiseSalary(int percent){

// The code to increase the

// hourly rate goes here

System.out.println(
"Class
Consultant: Increasing hourly rate by "+
percent
+ "%");
return
true;

}
}




Designer of the class Person may not know
specifics of the raising salary process, which does not stop him from calling
the method raiseSalary.
Programmers writing subclasses are forced to write implementation of this
method according to its signature declared in the abstract class. If they
declare a method raiseSalary
with a different argument list, this will be considered a method
overloading
and the subclass will remain abstract. The class Promoter in the Listing 4
shows how to use our classes Employee and Consultant for promoting workers.




__________________
http://livetolead.blogspot.com/
all the best
Arise Awake N Stop Not Until Ur Goal Is Reached!
sowmya571 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 16-02-06, 12:24 PM   #5 (permalink)
Moderator
 
Join Date: Feb 2006
Posts: 1,413
Thanks: 0
Thanked 9 Times in 8 Posts
Thanks: 0
Thanked 9 Times in 8 Posts
Rep Power: 18 sowmya571 has disabled reputation
hello



if u ahve doubts u can ask again



bye



sowmya




__________________
http://livetolead.blogspot.com/
all the best
Arise Awake N Stop Not Until Ur Goal Is Reached!
sowmya571 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +6.5. The time now is 02:48 AM.





Search Engine Optimization by vBSEO 3.1.0