We can not call the non static methods from a sttic methods
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1 • Share
We can not call the non static methods from a sttic methods
Dear Student,
All static methods work alike and you are not right in sense that we call non static method in static method by providing it a reference to the belonging object.
e.g. look at following code:
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Main m1 = new Main();
m1.disp1();
NewClass.disp();
}
public void disp1(){
System.out.println("its a non static method");
}
}
public class NewClass {
public static void disp(){
System.out.println("its a static method");
NewClass n1 = new NewClass();
n1.disp1();
}
public void disp1(){
System.out.println("its a non static method");
}
}
Output:
run:
its a non static method
its a static method
its a non static method
All static methods work alike and you are not right in sense that we call non static method in static method by providing it a reference to the belonging object.
e.g. look at following code:
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Main m1 = new Main();
m1.disp1();
NewClass.disp();
}
public void disp1(){
System.out.println("its a non static method");
}
}
public class NewClass {
public static void disp(){
System.out.println("its a static method");
NewClass n1 = new NewClass();
n1.disp1();
}
public void disp1(){
System.out.println("its a non static method");
}
}
Output:
run:
its a non static method
its a static method
its a non static method
WikiLeaks- Monstars
- Posts : 26
Join date : 2011-05-29
Similar topics
» Phone Call Recording Systems Automatic call Recorder Phone Technology Software
» Miss Call Finder | Miss Call Tracker PK
» Differentiate between static and nonstatic members in java 2011
» Methods of Recruitment
» STA630 - Research Methods GDB 2
» Miss Call Finder | Miss Call Tracker PK
» Differentiate between static and nonstatic members in java 2011
» Methods of Recruitment
» STA630 - Research Methods GDB 2
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Sat May 04, 2024 11:49 am by ali001
» house disrepair claims
Thu May 02, 2024 4:29 pm by Ibad Khan Buledi
» Bounce n Bang: Physics puzzler
Thu May 02, 2024 11:39 am by ali001
» AIChatSY - AIChatbot Assistant
Wed May 01, 2024 10:48 am by ali001
» Storybook Magic App
Tue Apr 30, 2024 7:06 pm by ali001
» Flower Book Match3 Puzzle Game
Tue Apr 30, 2024 12:17 pm by ali001
» Avian Influenza Symptom in Chickens "Bird Flu H5N1 Virus" Vet learning materials, Poultry Farming
Sat Apr 27, 2024 9:57 am by Ibad Khan Buledi
» Aloha Planner - Note-Taker
Thu Apr 11, 2024 4:52 pm by ali001
» Streaming Guide Film TV Series
Tue Apr 09, 2024 9:39 pm by ali001