Showing posts with label Interfaces. Show all posts
Showing posts with label Interfaces. Show all posts

Tuesday, November 15, 2022

Interfaces in Java

package inhert;
public class Inhert  {
 public interface person{
         void name(String n);
         void age(int a );
         void clas(int c);
    }
   
    public static class usman implements person{
    public  void name(String n){
        System.out.println("Usman name= "+n);
    }
    public void age(int a){
        System.out.println("Usman age= "+a);
    }
    public void clas(int c){
        System.out.println("Usman class= "+c);
    }
    }
   
    public static class usama implements person{
    public void name(String n){
        System.out.println("Usman name= "+n);
    }
    public void age(int a){
        System.out.println("Usman class= "+a);
    }
    public void clas(int c){
        System.out.println("Usman class= "+c);
    }  
    }
   
  
       public static void main(String[] args){
           usama obj=new usama();
           obj.name("Usama hussain");
           obj.age(20);
           obj.clas(10);
          
           usman obj1=new usman();
           obj1.name("Usman Siddique");
           obj1.age(21);
           obj1.clas(9);
}   }
================================
An interface is a reference type in Java, it is similar to class, it is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
Along with abstract methods an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
Writing an interface is similar to writing a class. But a class describes the attributes and behaviours of an object. And an interface contains behaviours that a class implements.
Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.
An interface is similar to a class in the following ways:
  • An interface can contain any number of methods.
  • An interface is written in a file with a .java extension, with the name of the interface matching the name of the file.
  • The byte code of an interface appears in a .class file.
  • Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name.
However, an interface is different from a class in several ways, including:
  • You cannot instantiate an interface.
  • An interface does not contain any constructors.
  • All of the methods in an interface are abstract.
  • An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final.
  • An interface is not extended by a class; it is implemented by a class.
  • An interface can extend multiple interfaces.

Declaring Interfaces:

The interface keyword is used to declare an interface.

Thursday, February 25, 2016

Simple CV Using HTML and CSS .... About Me Example

HTML:-


<div class="bod">
          <div class="pro">
                 <img src="a.jpg" class="img1">
          </div>
<div class="intro">
   <p class="p1">Hafiz Muhammad Usman Siddique</p>
    <p class="p2">"I am usman.A little boy with big attributes.An empty pocketed with big                ideas in mind.A courage to do big thing but did'nt do any thing yet .lol"</p>

</div>
<div class="second">

<table class="he"  align="center" cellspacing="31px">
<tr><th colspan="3">Skills<hr></th></tr>
<tr>
<td>CSS</td>
<td>HTML</td>
<td>PHP</td></tr>
</table>

<table border="1" align="center" >
<tr><th colspan="2">EDUCATION</th><th colspan="2">INTERNSHIP</th><th colspan="2">PROJECTS</th><th colspan="2">CONTACT</th></tr>
<tr><th rowspan="2">School:</th><td>F G Public School</td>
<th rowspan="2">Ptcl:</th><td>F G Public School</td>
<th rowspan="2">Web:</th><td>F G Public School</td>
<th rowspan="2">Email:</th><td>m7u786@gmail.com</td></tr>
<tr><td>2001-2010</td><td>2001-2010</td></tr>
<tr><th rowspan="2">Collage:</th><td>HITEC Collage For Boys</td>
<th rowspan="2">Lrims:</th><td>F G Public School</td>
<th rowspan="2">Android:</th><td>F G Public School</td>
<th rowspan="2">Mob No:</th><td>03075230948</td></tr>
<tr><td>2011-2012</td></tr>
<tr><th rowspan="2">University:</th><td>Comsats Wah Campus</td>
<th rowspan="2">Codingboths:</th><td>F G Public School</td>
<th rowspan="2">Desktop:</th><td>F G Public School</td>
<th rowspan="2">Address:</th><td>HIT Taxila Cantt,Rawalpindi</td></tr>
<tr><td>2013-2017</td></tr>
<tr><th colspan="2"></th><th colspan="2">Description</th><th colspan="2">Description</th><th colspan="2">Description</th></tr>
<tr><th colspan="2"><pre>i
e-resizee
e</pre></th><th colspan="2"></th><th colspan="2"></th><th colspan="2">.</th></tr>

</div>
</div>



CSS:-


<style>
.he td{border-radius:100px;width:100px;height:100px;text-align:center;border:1px solid ;}
.he {padding:15px;}
.p1{font-weight:bold;font-size:20px;text-align:center;}
.pro{padding-left:43%;padding-top:5%;background-color: #aff;}
.intro{background-color:#eee;}
.second{background-color:#ee9;}
.img1{width: 200px;border-radius: 100px;height: 200px; }
.p2{text-align:center;}body{background-color:whitesmoke;}
.bod{background-color:#eee}
</style>




Sunday, September 13, 2015

Interface /Abstract Classes in C++

An interface describes the behavior or capabilities of a C++ class without committing to a particular implementation of that class.
The C++ interfaces are implemented using abstract classes and these abstract classes should not be confused with data abstraction which is a concept of keeping implementation details separate from associated data.
A class is made abstract by declaring at least one of its functions as pure virtual function. A pure virtual function is specified by placing "= 0" in its declaration as follows:



#include <iostream.h>

class Shape

{

public:

// pure virtual function providing interface framework.

virtual int getArea() = 0;

void setWidth(int w)

{

width = w;

}

void setHeight(int h)

{

height = h;

}

protected:

int width;

int height;

};



class Rectangle: public Shape

{

public:

int getArea()

{

return (width * height);

}

};

class Triangle: public Shape

{

public:

int getArea()

{

return (width * height)/2;

}

};



int main(void){

Rectangle Rect;

Triangle Tri;

Rect.setWidth(5);

Rect.setHeight(7);

cout << "Total Rectangle area: " << Rect.getArea() << endl;

Tri.setWidth(5);

Tri.setHeight(7);

cout << "Total Triangle area: " << Tri.getArea() << endl;

return 0;

}

Interfaces in C#

An interface is defined as a syntactical contract that all the classes inheriting the interface should follow. The interface defines the 'what'part of the syntactical contract and the deriving classes define the 'how'part of the syntactical contract.
Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow.
Abstract classes to some extent serve the same purpose, however, they are mostly used when only few methods are to be declared by the base class and the deriving class implements the functionalities.



using System;
namespace ArrayApplication
{
    public interface person{
         void name(string n);
         void age(int a );
         void clas(int c);
    }
   
    public class usman : person{
    public  void name(string n){
        Console.WriteLine("Usman name= "+n);
    }
    public void age(int a){
        Console.WriteLine("Usman age= "+a);
    }
    public void clas(int c){
        Console.WriteLine("Usman class= "+c);
    }
    }
   
    public class usama : person{
    public void name(string n){
        Console.WriteLine("Usman name= "+n);
    }
    public void age(int a){
        Console.WriteLine("Usman class= "+a);
    }
    public void clas(int c){
        Console.WriteLine("Usman class= "+c);
    }  
    }
   
   public class test
   {
       public static void Main(String[] args){
           usama obj=new usama();
           obj.name("Usama hussain");
           obj.age(20);
           obj.clas(10);
         
           usman obj1=new usman();
           obj1.name("Usman Siddique");
           obj1.age(21);
           obj1.clas(09);
       }
   }
}

=========================================
using System;
namespace ArrayApplication
{
    public interface abc{
         void fun();
              }

   public class MyArray : abc
   {
                                                         public void fun(){
                                                        Console.WriteLine("this is defination of interface fun");
                                                       }
                                                       static void Main(string[] args){
                                                       MyArray obj=new MyArray();
                                                      obj.fun();
                                                      }    }    }