M1088184 Assignment6

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Assignment 6

Given example for Marker and functional interface.

Marker Interface
package com.app;

import java.util.Scanner;

public class Product implements Cloneable {

int pid;
String pname;
double pcost;

public Product(int pid, String pname, double pcost) {


super();
this.pid = pid;
this.pname = pname;
this.pcost = pcost;
}
public void showDetails() {
System.out.println("Product ID:"+pid);
System.out.println("Product Name:"+pname);
System.out.println("Product Cost :"+pcost);
}

public static void main(String[] args)throws CloneNotSupportedException {


// TODO Auto-generated method stub
Scanner sc = new Scanner (System.in);
System.out.println("Enter product ID");
int pid = sc.nextInt();
System.out.println("Enter product name");
String pname = sc.next();
System.out.println("Enter product Cost");
double pcost = sc.nextDouble();

Product p1 = new Product(pid,pname,pcost);


Product p2 = (Product) p1.clone();

p1.showDetails();

}
Output:

Enter product ID
6
Enter product name
soap
Enter product Cost
66
Product ID:6
Product Name:soap
Product Cost :66.0

Functional interface
package com.app;

public class Test {

public static void main(String[] args) {

// TODO Auto-generated method stub


new Thread(new Runnable() {
@Override public void run()
{
System.out.println("New Thread Created");
}
}).start();

Output:

New Thread Created

You might also like