adspace
Can you have a constructor in abstract class?
Answer Posted / kundan ranjan
ya
you can write constructor in abstract class
becoz,construct are use in abstract class only for initialize the state(variables) of class
you know that all the variable are allowed inside the abstract class
if you not initialize the variable at declaration time then you have need constructor becoz
you have no any alternative method to initialize the state thats why constructor are allowed inside
abstract class
see example:
abstract class hello
{
int x;
abstract void m1();
hello(int x)
{
this.x=x;
System.out.println(x);
}
}
class Hai extends hello
{
Hai(int x)
{
super();
}
void m1()
{
System.out.println("asdf");
}
}
class Lab84
{
public static void main(String as[])
{
hello h=new Hai(12);
h.m1();
h.m2();
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Differentiate between static and non-static methods in java.
What is the difference between equals() and == in java?
What is parsing in java?
Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example
What is the difference between break and continue statements?
How to sort array in descending order in java?
What is an object in java and how is it created?
Write a program to find the whether a number is an Armstrong number or not?
What are the differences between heap and stack memory in java?
Realized?
What is a classloader in java?
How to create a base64 decoder in java8?
Explain public static void main(string args[]) in java.
What is java string pool?
What is a constructor overloading in java?