Java / Android Developer, Trainer, Writer, Speaker

Sunday, February 1, 2015

On 9:29 PM by Unknown in ,    4 comments

Like the article?

Hi guys!
Today we are going to learn couple of java OOP ( Object Oriented Programming ) concepts.
Before starting, go through this article: JAVA Tutorial : Inheritance Example Codes




Abstract Class and Example in JAVA:




package interfacez;

/*
 
 This is a simple abstract class. An abstract class is a call of which no object 
 can be created. Use 'abstract' keyword to make a class abstract. 
 Methods can be abstract too. If in a class a method is abstract the class must have
 to be abstract.
 */
public abstract class myabstractclass {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	/*
	 An abstract method must not have a body. 
	 In an abstract class you can have a non abstract method.
	 */
	abstract public void specialAbstractMethod();

}


Java interface: Creating Java Interface




package interfacez;
/* This is my interface. I will inherit this from my main class.
  This is also the java super class for my main class from which i will
  call this file and access those methods.



*/
public interface createinterface {

	// creating four methods
	public void website();
	public void android_app();
	public void ios_app();
	public void windows_app();
}





Java interface: Calling methods from main class




package interfacez;

/*
 Interface is a type that brings behaviors which a class can implement according to its need.
 implements keyword is used to implement an interface in a java class.
 Interface is a class like thing which is 100% abstract. A class can implement 
 any number of interfaces that it wants.If needed interface can be extended using
 inheritance concept of OOP( Object Oriented Programming. )
 
 
 */
public class myinterfaceclass implements createinterface{

	public static void main(String[] args) {
		/* creating object for my class, so that i can call the methods that have
		come from interface.
	*/
		myinterfaceclass Apps_Object = new myinterfaceclass();
		
		/*
		 Calling the methods using my object.
		 
		 */
		Apps_Object.website();
		Apps_Object.ios_app();
		Apps_Object.android_app();
		Apps_Object.windows_app();
		
	}
	
	/*
	 Overriding the abstract methods that have come from interface.
	 
	 */ 
	
	public void website(){
		System.out.println("Java tutorials on my website.");
	}
	public void android_app(){
		System.out.println("PHP tutorials on my android app.");		
	}
	public void ios_app(){
		System.out.println("JavaScript tutorials on my iOS App.");
	}
	public void windows_app(){
		System.out.println("C Sharp ( C# ) on my windows app.");
	}

	
}



Hope this helps you! don't forget to share and subscribe!

  Read More: Differences Between Programmers and Coders

4 comments:

  1. As stated by Stanford Medical, It's indeed the ONLY reason this country's women get to live 10 years longer and weigh on average 19 KG lighter than we do.

    (And by the way, it is not related to genetics or some secret exercise and absolutely EVERYTHING around "HOW" they are eating.)

    BTW, I said "HOW", not "WHAT"...

    TAP this link to uncover if this brief quiz can help you discover your real weight loss potential

    ReplyDelete