Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners core java, static
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


AmanDeep
core java, static
1 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners


Dear sir, in java non-static fields can not be accessed in a static field.
But if we create an object of class type in static field and then call non-static field in it, it works fine as in following program ( Ultimately this is what we do in static main method). So is right to say that practically its not impossible to call non-static fields in static fields.

//Static.java
public class Static
{

static void stat()
{
Static st1 = new Static();
st1.stat1();
}

void stat1()
{
System.out.println("You can call me within static method with the help of class object");

}


public static void main(String args[])
{
Static st1 = new Static();

st1.stat();

}
}

Advertisement
View Answers

August 10, 2010 at 4:09 PM


Hi Friend,

Yes, it is right.

Thanks


Related Tutorials/Questions & Answers:
core java, static - Java Beginners
core java, static  Dear sir, in java non-static fields can not be accessed in a static field. But if we create an object of class type in static field and then call non-static field in it, it works fine as in following program
static in java
static in java  what is the need to go static? what use
Advertisements
core java
core java  Hi, can any one exain me the concept of static and dynamic loading in core java
core java
core java  how to display characters stored in array in core java
core java
core java  basic java interview question
CORE JAVA
CORE JAVA  CORE JAVA PPT NEED WITH SOURCE CODE EXPLANATION CAN U ??   Core Java Tutorials
core java
core java  i need core java material   Hello Friend, Please visit the following link: Core Java Thanks
core java
core java  Hi, can any one expain me serialization,Deseralization and exterenalization in core java
Java static method
Java static method  Can we override static methods
Java static import
Java static import  What is the use of static import
Core Java
Core Java  What is the significance of static synchronized method? Why do we have the method declared as static synchronized
Core JAva
Core JAva  how to swap 2 variables without temp in java
core java
core java  how can we justify java technology is robust
Static & Instance variables in java
Static & Instance variables in java  What are the Difference between Static & Instance variables in java
Static Method in Java
Static Method in Java  Is Overriding Static methods possible in java? If Yes, How
CORE JAVA
CORE JAVA  Static methods can be participated in inheritance? What is static keyword? What is static keyword? How to write code for static factory method? What is mutable and immutable
class static - Java Beginners
information on Static in Java visit to : http://www.roseindia.net/java/beginners...class static  When do we declare a member of a class static?  Hi friend, public class HowToAccessStaticMethod{ int i; static int j
Core Java
Core Java  can any one please tell me the difference between Static and dynamic loading in java???   The static class loading is done through the new operator while dynamic class loading is achieved through Run time
core java
core java  public class Check { public static void main(String[] args) { System.out.println(11^2); } } how it is work???? plzz explain
CORE JAVA
CORE JAVA  What is Garbage collection in java? What is the role of a developer for garbage collection
core java
core java  its compulsory to save file name and class name is same in java
Core Java
Core Java  How to execute cmd command through java?? Give Code of them
core java
core java  write a java program to view product details from product table
Core Java
Core Java  Is Java supports Multiple Inheritance? Then How ?   There is typo the question is , What is Marker Interface and where it can... implements markerImp{ } public class TestInstanceOf { public static void main(String
Core Java
Core Java  Hi, Can any one please share the code for Binary search in java without using builtin function
Core Java
Core Java  Please write a Java Program to design login form and store the values in file & validate and display the MainForm
core java
core java  In java primitive variables will get its default value automatically after declaration. Then why it is mandatory to initialize a variable before using
core java
core java  public static void main(String k[]) Is it possible to pass the Integer type arr instead of String type in main method?(replacing String than Integer) if possible.. how to write code
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
core java
core java  java program using transient variable   Hi...() { return "Name=" + name + "\n Password=" + pass; } public static void main(String..., visit the following link: http://www.roseindia.net/help/java/t/transient-java
 

 

 

DMCA.com