Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyProgram
- {
- int count = 0;
- public static void main(String[] args)
- {
- System.out.println(count);
- }
- }
- Main.java:6: error: non-static variable count cannot be referenced from a static context
- System.out.println(count);
- ^
- public static void main (String[] args)
- {
- try
- {
- MyProgram7 obj = new MyProgram7 ();
- obj.run (args);
- }
- catch (Exception e)
- {
- e.printStackTrace ();
- }
- }
- // instance variables here
- public void run (String[] args) throws Exception
- {
- // put your code here
- }
- class Programm {
- public static void main(String[] args) {
- Programm programm = new Programm();
- programm.start();
- }
- public void start() {
- // can now access non-static fields
- }
- }
- import java.io.*;
- class HelloWorld {
- int myInt; // this is a class variable that is unique to each object
- static int myInt2; // this is a class variable shared by all objects of this class
- static void main (String [] args) {
- // this is the main entry point for this Java application
- System.out.println ("Hello, Worldn");
- myInt2 = 14; // able to access the static int
- HelloWorld myWorld = new HelloWorld();
- myWorld.myInt = 32; // able to access non-static through an object
- }
- }
- public class MyProgram7 {
- static Scanner scan = new Scanner(System.in);
- static int compareCount = 0;
- static int low = 0;
- static int high = 0;
- static int mid = 0;
- static int key = 0;
- static Scanner temp;
- static int[]list;
- static String menu, outputString;
- static int option = 1;
- static boolean found = false;
- public static void main (String[]args) throws IOException {
- ...
- public class Myprogram7 {
- Scanner scan;
- int compareCount = 0;
- int low = 0;
- int high = 0;
- int mid = 0;
- int key = 0;
- Scanner temp;
- int[]list;
- String menu, outputString;
- int option = 1;
- boolean found = false;
- private void readLine() {
- }
- private void findkey() {
- }
- private void printCount() {
- }
- public static void main(String[] args){
- Myprogram7 myprg=new Myprogram7();
- myprg.readLine();
- myprg.findkey();
- myprg.printCount();
- }
- }
- NamCls.NamFnc();
- System.out.println();
- NamCls NamObjVar = new NamCls();
- NamObjVar.NamFnc();
- public class NamCls
- {
- public static void main(String[] args)
- {
- PlsPrnFnc("Tst Txt");
- NamCls NamObjVar = new NamCls();
- NamObjVar.PrnFnc("Tst Txt");
- }
- static void PlsPrnFnc(String SrgPsgVal)
- {
- System.out.println(SrgPsgVal);
- }
- void PrnFnc(String SrgPsgVal)
- {
- System.out.println(SrgPsgVal);
- }
- }
- public class NamCls
- {
- public static void main(String[] args)
- {
- NamTicCls NamTicVaj = new NamTicCls();
- NamTicVaj.PrnFnc("Tst Txt");
- NamCls NamObjVar = new NamCls();
- NamNicCls NamNicVar = NamObjVar.new NamNicCls();
- NamNicVar.PrnFnc("Tst Txt");
- }
- static class NamTicCls
- {
- void PrnFnc(String SrgPsgVal)
- {
- System.out.println(SrgPsgVal);
- }
- }
- class NamNicCls
- {
- void PrnFnc(String SrgPsgVal)
- {
- System.out.println(SrgPsgVal);
- }
- }
- }
- class StaticTest {
- static int a;
- int b;
- int c;
- }
- class StaticTest {
- public void display() {
- System.out.println("Static Test");
- }
- public static void main(String []cmd) {
- display();
- }
- }
- class StaticTest {
- public static void main(String []cmd) {
- display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement