Can you have Abstract class main() method?
Yes, definitely, because main() is a concrete method and abstract class allows concrete methods. But what you can you do with the main() when you are not allowed to create objects of abstract classes. But, you can create objects of another class and use other class methods by composition.
Following program illustrates on Abstract class main()
class Test
{
int x = 10;
public void display()
{
System.out.println("Hello 1");
}
}
public abstract class Demo
{
public static void main(String args[])
{
Test t1 = new Test();
System.out.println("From abstract class main(): " + t1.x);
t1.display();
}
}

Output screen on Abstract class main()
Observe, Demo is declared abstract and contains main() method. In the main() method, object of Test class t1 is created and the members of Test are called.
Other interested topics on abstract classes
1. Can you have a constructor in abstract class?
2. Can you have all concrete methods in an abstract class without even one abstract method as in the above Demo class?
3. Can an interface have constructor?
4. Can abstract method be static?
5. Why the methods of an interface should be overridden as public only?
Sir,
I have 4 years of experience only in manual testing. I have joined Java and Selenium Course it is helpful to my career. Please let me know about this.
Thanks,
Umesh
Because you are on testing side, it is a good idea.
Hi Sir,
I have 3 years of experience in manual testing and now I want to change my skills from testing to Java.
Please provide your suggestion how to do.
To change, first your employer may not accept as he will not loose a programmer of 3 years experience in testing. You must show a strong reason for shifting. My advice is pass Java Certified Programmer and Java Web component developer exams. Then keep the certificates before your employer and express you are interested in Java programming. Request them to shift and the request should go on whenever opportunity comes.
sir , i m fresher and now i’m working in IT department of company .it is possible to shift from networking to coding after experience.
You must show good reason for shifting. Ask me reasons, I get you later.
my interest in software development ,i do this job for because something is better than nothing .. means i m searching coding job last 2-3 months but did not find any job of software becoz of this i joined this job sir
plz suggest sir and guide him what i do next
What job you are doing right now? What is your qualification? When did you pass?
sir ,i m doing IT Executive job in company my work related to network ,hardware ,backup,installation .
i m completed my b.tech IT in 2013
sir plz reply as soon as possible
What is your query?
sir can i shift networking to coding or development job after one year or more experience , its possible or not ??
Depends your convincing the employer.
Hi Sir,
Recently i got job as test engineer is it good Field to Settle.need Suggestion from you sir
If you are fresher, simply accept without second thoughts else I do not advice. Once accepted as test engineer as fresher, work for 1 year and then ask me how to shift to coding, I will give advice; it is possible to shift from testing to coding.
Thanks sir
Nice website….got some fair knowledge in Java after started using this website. Thank you so much Mr. Nageswara Rao.
An abstract method cannot be declared as static. static method should contains the method body.If you declare any method as abstract & static then it will generates compile time error:- Illegal combination of modifiers : abstract & static
Yes we can have all the concrete methods in abstract class without even a single abstract method. Try this code.
eg:-
public abstract class A
{
public void show1()
{
System.out.println(“hello from show1”);
}
public void show2()
{
System.out.println(“hello from show2”);
}
}
class B extends A
{
public static void main(String args[])
{
B ob=new B();
ob.show1();
ob.show2();
}
}
then what is the use of abstract in that programm
There is no necessity. It is only an example of possibility. Realtime, no application. It is matter of interview teasing.
nice website sir
Sir ,
This is good website .I really learn so much.thank u very much sir..
Nice to hear from you. Advice your friends also to derive knowledge from this web site.
The very nice site that I have ever visited. Thank you for providing most valuable explanations and examples. I really appreciate yours…
regards,
Rajaguru.
Thanks for your appreciation. Tell your friends also.
Hello Sir,
Under what circumstance we go for this option? Can you give me a Real Time example for this?
Thanks,
Harish Raj