Concepts of Interface, Abstract and Class.
The Hire-ache of these concepts is
What is Interface?? Why It's introduced in Java??
Multiple Inheritance is not available in Java, because It causes Diamond problem which encounters the Program failure so, Interface is introduced in java.
Interface
Interface <name>
method_name(); //Should not implement
class <class_name> implements <name>
{
method_name()
{
System.out.print("The method is running");
}
public static void main(String args[])
{
class_name object_name = new class_name();
object_name.method_name();
}
}
Condition for the Interface
Abstract:
The next level is Abstract of Interface. An abstract method allows non-abstract method also. The keyword "extends" is used to Inherit the abstract class into the Class.
Example:
abstract <class_name>
abstract abstract_method_name(); //Should not implement
void method_name
{
System.out.println("The non-abstract method is running");
}
class <class_name> extends <name>
{
abstract_method_name()
{
System.out.print("The method is running");
}
public static void main(String args[])
{
class_name object_name = new class_name();
object_name.method_name();
}
}
Conditions:
You should Override the abstract method in the Class
Class:
Class is the next level of the abstract
class <class_name>
{
void method_name()
{
System.out.println("Method is running");
}
void method_name2()
{
System.out.println("Method-2 is running");
}
public static void main(String args[])
{
System.out.println("Main method triggered");
class_name object_name = new class_name();
object_name.method_name();
}
}
Class method running normally.
The Hire-ache of these concepts is
- Interface
- Abstract
- Class
What is Interface?? Why It's introduced in Java??
Multiple Inheritance is not available in Java, because It causes Diamond problem which encounters the Program failure so, Interface is introduced in java.
Interface
Interface <name>
method_name(); //Should not implement
class <class_name> implements <name>
{
method_name()
{
System.out.print("The method is running");
}
public static void main(String args[])
{
class_name object_name = new class_name();
object_name.method_name();
}
}
Condition for the Interface
- You should not implement anything in the Interface.
- You should implement all the methods which defined in the Interface should implement in the Class.
- We can Pass the arguments in the Interface Ex. method_name(int a, int b);
Abstract:
The next level is Abstract of Interface. An abstract method allows non-abstract method also. The keyword "extends" is used to Inherit the abstract class into the Class.
Example:
abstract <class_name>
abstract abstract_method_name(); //Should not implement
void method_name
{
System.out.println("The non-abstract method is running");
}
class <class_name> extends <name>
{
abstract_method_name()
{
System.out.print("The method is running");
}
public static void main(String args[])
{
class_name object_name = new class_name();
object_name.method_name();
}
}
Conditions:
You should Override the abstract method in the Class
Class:
Class is the next level of the abstract
class <class_name>
{
void method_name()
{
System.out.println("Method is running");
}
void method_name2()
{
System.out.println("Method-2 is running");
}
public static void main(String args[])
{
System.out.println("Main method triggered");
class_name object_name = new class_name();
object_name.method_name();
}
}
Class method running normally.
No comments:
Post a Comment