- class Sb
- {
- static int x = 20;
- static int y = 30;
- static
- {
- System.out.println("Static Block Invokes");
- }
- }
- class Tsb
- {
- public static void main(String...a)
- {
- System.out.println(Sb.x);
- System.out.println(Sb.y);
- }
- }
- Output:
- Static Block Invokes
- 20
- 30
- class Temp
- {
- void show()
- {
- System.out.println("method of Temp ");
- }
- }
- class Demo
- {
- static int x=20;
- static int y=30;
- static
- {
- Temp t = new Temp();
- t.show();
- }
- }
- class Xy
- {
- public static void main(String...a)
- {
- System.out.println(Demo.x);
- System.out.println(Demo.y);
- }
- }
- Output:
- Temp.java:27: error: class, interface, or enum expected { ^ 1 error
- class Temp
- {
- void show()
- {
- System.out.println("method of Temp ");
- }
- }
- class Demo
- {
- static int x=20;
- static int y=30;
- static
- {
- System.out.println(x);
- System.out.println(y);
- System.out.println("HELLO");
- }
- }
- class Xy
- {
- static
- {
- Temp t = new Temp();
- t.show();
- }
- }
- Output:
- Error: Main method not found in class Xy, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
- class Temp
- {
- void show()
- {
- System.out.println("method of Temp ");
- }
- }
- class Demo
- {
- static int x=20;
- static int y=30;
- static
- {
- System.out.println(x);
- System.out.println(y);
- System.out.println("HELLO");
- }
- }
- class Xy
- {
- public static void main(String...a)
- {
- Temp t = new Temp();
- t.show();
- }
- }
- Output:
- method of Temp
| Copyright ©2016 | All Rights Reserved |
| Design by Uves Khan |