Skip to main content

Interfaces

Java Programming


Interfaces

The interface keyword takes the abstract concept one step further. You could think of it as a “pure” abstract class. It allows the creator to establish the form for a class: method names, argument lists and return types, but no method bodies. An interface can also contain data members of primitive types, but these are implicitly static and final. An interface provides only a form, but no implementation.


 An interface says:  
“This is what all classes that implement this particular interface will look like.” Thus, any code that uses a particular interface knows what methods might be called for that interface, and that’s all. So the interface is used to establish a “protocol” between classes.


The syntax for defining an interface is similar to creating a new class:  


interface <InterfaceName>
 {    
     // constant declarations, if any 
     
     static final <data type> <variable name>  =  <value>;  
   
   // method signatures
   
     <return type> <methodName>(<parameter list>);  
}


watch me on Instagram

https://www.instagram.com/abhishek_av1/




Comments

Popular posts from this blog

Concept of OOPS

Java Programming This are the basic concept of OOPS. 1. Object 2. Class 3. Data abstraction 4. Data encapsulation 5. Inheritance 6. Polymorphism 7. Dynamic binding Java Classes/Objects Java is an object-oriented programming language. Everything in Java is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has  attributes , such as weight and color, and  methods , such as drive and brake. A Class is like an object constructor, or a "blueprint" for creating objects. Create a Class To create a class, use the keyword  Myclass.java Create an Object In Java, an object is created from a class. We have already created the class named  MyClass , so now we can use this to create objects. To create an object of  MyClass , specify the class name, followed by the object name, and use the keyword  new : Example=> public class Myclass{ int x=10;...

DBMS LEARNING SHEET

                                                            Types of DATA Structured data are facts concerning objects and events. The most important structured data are numeric, character, and dates. Structured data are stored in tabular form. Unstructured data are multimedia data such as documents, photographs, maps, images, sound, and video clips. Unstructured data are most commonly found on Web servers and Web-enabled databases. Database A database is a collection of data that is organised in such a way that it provides efficient retrieval of desired information. This collected data could be in any format like printed, audio, electronic and graphic. Consider an example of an address book, it is also a database that provides information of personal contacts of persons. DBMS A Database Mana...

ALGORITHMS MCQ SHEET

1.  Consider the following two functions. What are time complexities of the   functions? a) O(2^n) for both fun1()   and   fun2() b) O(n) for fun1() and O(2^n) for fun2() c) O(2^n) for fun1() and O(n)   for   fun2() d) O(n) for both fun1() and   fun2()   2.  Fill in the blank: f(n) = O(g(n)) if and only if   g(n) =   . 3.  To sort a list with n elements, the insertion sort begins   with   the   element. a)   First b)   Second c)   Third d) Fourth 4.  List obtained in third pass of selection sort for list 3, 5, 4, 1,   2   is   . a) 1, 2, 4,   3, 5 b) 1, 2, 3, 4, 5 c) 1, 5, 4,   3, 2 d) 3, 5, 4, 1, 2 5.  The complexity of Bubble sort algorithm   is: a)   O(n) b) O(log n) c) O(n 2 ) d) O(n log n) 6.  The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is: a) T(n)...