0% found this document useful (0 votes)
8 views6 pages

Method Refrence Assignment

The document contains multiple Java classes demonstrating the use of functional interfaces and method references. Each 'Que' class showcases different functionalities such as displaying messages, performing calculations, and creating objects using method references. The examples illustrate the application of lambda expressions and method references in Java programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Method Refrence Assignment

The document contains multiple Java classes demonstrating the use of functional interfaces and method references. Each 'Que' class showcases different functionalities such as displaying messages, performing calculations, and creating objects using method references. The examples illustrate the application of lambda expressions and method references in Java programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

que1

package que1;

interface first{
void disp();
}

class second {
void fun() {

[Link]("in fun");
}
}

public class Que1 {

public static void main(String[] args) {


// TODO Auto-generated method stub
second sce=new second();
first ref=sce::fun;
[Link]();

// first fir=()->{
// [Link]("in disp");
// };
// [Link]();

first fir1=()->{
[Link]();
};
[Link]();

Que2

package que2;
interface third{
void show(int num);
}

class sample{
void disp(int num) {
[Link](num);
}
}

public class Que2 {

public static void main(String[] args) {


// TODO Auto-generated method stub
sample s2=new sample();
third th=(a)->{
[Link](a);
};
[Link](500);

third th1 = s2::disp;


[Link](500);

Que3

package que3;
interface fifth{
int add(int a,int b);
}

class Math1{
int calc(int a, int b) {
return a+b;
}
}

public class Que3 {

public static void main(String[] args) {


// TODO Auto-generated method stub
Math1 m =new Math1();
fifth fif=(a,b)->{
return [Link](a, b);
};
[Link]([Link](10, 20));

fifth fif1 = m::calc;


[Link]([Link](10, 20));

Que4

package que4;

interface sixth{
void disp5();
}

class sample {
void fun1() {
[Link]("in fun1");
}
}

public class Que4 {

public static void main(String args[]) {


sample s =new sample();

sixth six = s :: fun1;

six.disp5();

Que5

package que5;

interface emp{
void show();
}
class myclass{
public myclass() {
[Link]("consructer");
}
}

public class Que5 {

public static void main(String[] args) {


// TODO Auto-generated method stub

emp e = myclass :: new;


[Link]();

emp e1=()->{
new myclass();
};[Link]();

Que6

package que6;

interface seventh{
void fun(int k);
}

class sample{
sample(int k){
[Link]("constructer" + k);
}
}

public class Que6 {

public static void main(String[] args) {


// TODO Auto-generated method stub
seventh sev= (k)->{
new sample(k);
};
[Link](10);

seventh sev1 = sample :: new;


[Link](100);

Que7

package que7;

class Student {
private String name;
private int age;

Student(String name,int age){


[Link]=age;
[Link]=name;

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
[Link] = name;
}

/**
* @return the age
*/
public int getAge() {
return age;
}

/**
* @param age the age to set
*/
public void setAge(int age) {
[Link] = age;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + "]";
}

}
interface Myinterface{
void show(Student ref);
}

public class Que7 {

public static void main(String[] args) {


// TODO Auto-generated method stub

Student s=new Student("vijay",18);


Myinterface in = [Link]::println;
[Link](s);

You might also like