code::
import java.io.*;
import java.util.*;
public class Global{
public static int flag=0;
}
interface filebackedfifoqueue
{
void put(String msg);
String get();
}
public class trying{
public static void main(String args[])throws IOException{
int ch=1;
String msg;
msg = new String();
while(ch!=0)
{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nMenu");
System.out.println("\n0.EXit");
System.out.println("\n1.Publisher");
System.out.println("\n2.Subscriber");
System.out.println("\nEnter your choice::");
ch = Integer.parseInt(stdin.readLine());
switch(ch)
{
case 0:
break;
case 1:
Global.flag++;
publisher();
break;
case 2:
if(Global.flag>=1)
// subscriber();
System.out.println("\nSubscriber part");
else
System.out.println("\nPublisher has not published anything yet!");
break;
}
}
}
void publisher()
{
if(Global.flag==1)
System.out.println("\nEnter the bounded size of the queue");
}
}
i need to use and increment a variable across 3 functions i.e:main,subscriber and publisher.
here is the code:
i am getting errors here:
The public type global must be declared in its own file.
Cannot make a static reference to the non-static method publisher() from the type trying