You are on page 1of 6

NATIONAL UNIVERSITY OF TECHNOLOGY

OBJECT ORIENTED PROGRAMMING

NAME: Sultan Mehmood

ROLL NO: F22607013


Batch: BS AI FALL 22
ASSIGNMENT NO: 03
SUBMITTED TO: MA’AM FARIA SAJJAD
DATE: 01/06
Code:
interface Animal {
int x = 10; // public static final int x = 10;

public void animalSound();


public void sleep();

}
class Pig implements Animal
{

public void animalSound() {

System.out.println("The pig says: wee wee");


}
public void sleep() {

// The body of sleep() is provided here


System.out.println("Zzz");
}
}
class Main1
{
public static void main(String[] args) {
Pig myPig = new Pig(); // Create a Pig object

myPig.animalSound();

myPig.sleep();
}

Output:

Code:
interface FirstInterface {
public void myMethod(); // interface method
}

interface SecondInterface {
public void myOtherMethod(); // interface method
}
class DemoClass implements FirstInterface, SecondInterface {
public void myMethod() {
System.out.println("myMethod Says: "+"Some text..");
}
public void myOtherMethod() {
System.out.println("myOtherMethod Says: "+"Some other text...");
}
}
class Main2 {
public static void main(String[] args) {
DemoClass myObj = new DemoClass();
myObj.myMethod();
myObj.myOtherMethod();

}
}

Output:

Code:

import java.util.Scanner;

interface Customer{

void input();

void output();
}
import java.util.Scanner;
class Service implements Customer {

String name;

double salary;

public void input() {


Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
name = sc.nextLine();
System.out.println("Enter salary:");
salary = sc.nextDouble();

public void output() {


System.out.println("Name: " + name);
System.out.println("Salary: " + salary);

}
}
class Main2{

public static void main(String[] args){


Customer c = new Service();
c.input();
c.output();

}
}
Output:

You might also like