Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. ///Java Lab 7
  2. ///Use Of Interface
  3.  
  4. /*
  5.  * To change this license header, choose License Headers in Project Properties.
  6.  * To change this template file, choose Tools | Templates
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. //ME.java
  11. package javalab7;
  12.  
  13. /**
  14.  *
  15.  * @author student
  16.  */
  17. public interface ME {
  18.    
  19.     public void task1(String s);
  20.     public void task2();
  21.     public void task3();
  22.  
  23. }
  24.  
  25. /*
  26.  * To change this license header, choose License Headers in Project Properties.
  27.  * To change this template file, choose Tools | Templates
  28.  * and open the template in the editor.
  29.  */
  30.  
  31. //Demo.java
  32.  
  33. package javalab7;
  34.  
  35. /**
  36.  *
  37.  * @author student
  38.  */
  39. public class Demo implements ME
  40. {
  41.     public void task1(String temp)
  42.     {
  43.         System.out.println(temp + "(TASK 1) is executed ");
  44.     }
  45.    
  46.      public void task2()
  47.     {
  48.         System.out.println("TASK 2 is executed ");
  49.     }
  50.       public void task3()
  51.     {
  52.         System.out.println("TASK 3 is executed ");
  53.     }
  54.       public void DemoOwn()
  55.     {
  56.         System.out.println("DemoOwn is executed ");
  57.     }
  58. }
  59.  
  60. //Demo2.java
  61.  
  62. package javalab7;
  63.  
  64. /**
  65.  *
  66.  * @author student
  67.  */
  68. abstract public class Demo2 implements ME{
  69.  
  70.     public void task1(String temp){
  71.    
  72.         System.out.println(temp + "(TASK 1) is executed from DEMO2");
  73.     }
  74.     public void task2(){}
  75.    
  76.    
  77. }
  78.  
  79. package javalab7;
  80.  
  81. /**
  82.  *
  83.  * @author student
  84.  */
  85. public class JavaLab7 {
  86.  
  87.     /**
  88.      * @param args the command line arguments
  89.      */
  90.     public static void main(String[] args) {
  91.         // TODO code application logic here
  92.      Demo obj = new Demo();
  93.      Demo2 obj2 = new Demo2();
  94.      
  95.        obj.task1("Hello");
  96.        obj.task2();
  97.        obj.task3();
  98.        obj.DemoOwn();
  99.    
  100.     obj2.task1("HI");
  101.     }
  102.    
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement