File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interfaces. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Interfaces." Watch "Interfaces." New topic
Author

Interfaces.

Amandeep Waraich
Ranch Hand

Joined: Jul 14, 2000
Posts: 56
Hi all,
I have this doubt in my mind. Can the interfaces and abstract classes have constructors? If yes, what is their significance as neither interfaces nor abstract classes can be instantiated.
Thanks in advance,
Aman
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
hi amandeep,
interface CAN NOT have constructors.
but abstract classes can have.
now when the constructor of abstract class is used ---
just run the following program and u'll come to know
program statrd
abstract class Person{
public Person()
{
//initialization common to all persons.
System.out.println("initialization common to all persons");

}
}
class Doctor extends Person
{
public Doctor()
{
//initialization specific to doctors.
System.out.println("initialization specific to doctors");
}
}
class Medi{
public static void main(String s[])
{
System.out.println("producing doctor");
Doctor d = new Doctor();
}
}
end of program
output of the above program is
-----------------------------------------
producing doctor
initialization common to all persons
initialization specific to doctors
-----------------------------------------
so u see in the constructor of abstract class u can do the initialization task which will be common to the sub classes
hope this helps
regards
dekasha


Amandeep Waraich
Ranch Hand

Joined: Jul 14, 2000
Posts: 56
Thanks a lot Deekasha, I got the idea...
Aman
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Interfaces.
 
Similar Threads
Difference Between Abstract Class and Interface
interface and abstract class
Instance Variable In abstarct classes
Doubt
Abstract class & Interface