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



Home Answers Viewqa Java-Beginners Class and Instance
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ninenan
Class and Instance
1 Answer(s)      3 years ago
Posted in : Java Beginners


class IdentifyMyParts { public static int x=7; public int y=3;}

What are the class variable? What are the instance variables?

What is the output from the following code:

IdentifyMyParts a = new IdentifyMyParts(); IdentifyMyParts b = new IdentifyMyParts(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println("a.y = " +a.y); System.out.println("b.y = " +b.y); System.out.println("IdentifyMyParts.x = " +a.x); System.out.println("b.x = " +b.x);


Advertisement
View Answers

October 27, 2011 at 12:35 PM


Instance variables are declared in a class, but outside a method. They are also called member or field variables. When an object is allocated in the heap, there is a slot in it for each instance variable value. Therefore an instance variable is created when an object is created and destroyed when the object is destroyed. Visible in all methods and constructors of the defining class, should generally be declared private, but may be given greater visibility.

Class variables are declared with the static keyword in a class, but outside a method. There is only one copy per class, regardless of how many objects are created from it. They are stored in static memory. It is rare to use static variables other than declared final and used as either public or private constants.

output is:

a.y=5
b.y=6
IdentifyMyParts.x=2
b.x=2


Related Tutorials/Questions & Answers:
Class and Instance
Class and Instance  class IdentifyMyParts { public static int x=7; public int y=3;} What are the class variable? What are the instance variables... = " +b.x);   Instance variables are declared in a class, but outside a method
INSTANCE
INSTANCE  PLEASE TELL ME THE EXACT MEANING OF INSTANCE?AND EXPLAIN
Advertisements
instance
instance  What is the exact need of declaring a variable as instance
variables are **called instance variables because they are created** whenever an object of the class is instantiated.
instance variables because they are created whenever an object of the class...variables are **called instance variables because they are created** whenever an object of the class is instantiated.  i am new to java and also
Instance variable in java
in java, they are as follows : Local variable Instance Variable class... in a class but outside method or constructor. Instance variable are created when.... Example : A code of program for Instance variableimport java.io.*; class
instance varaiable
instance varaiable  if we create a class which has two instance variable but don't create object of that class then what is called that instance variable??? bcoz they didn't allocate memory
what is instance
there is an value. int[] arr={1,2,3}; Instance - when there is a declaration for class...what is instance   what is the difference between instance and object   Instance refers to the copy of the object at a particular time
what is instance
there is an value. int[] arr={1,2,3}; Instance - when there is a declaration for class...what is instance   what is the difference between instance and object   Instance refers to the copy of the object at a particular time
what is instance
there is an value. int[] arr={1,2,3}; Instance - when there is a declaration for class...what is instance   what is the difference between instance and object   Instance refers to the copy of the object at a particular time
what is instance
there is an value. int[] arr={1,2,3}; Instance - when there is a declaration for class...what is instance   what is the difference between instance and object   Instance refers to the copy of the object at a particular time
what is instance
there is an value. int[] arr={1,2,3}; Instance - when there is a declaration for class...what is instance   what is the difference between instance and object   Instance refers to the copy of the object at a particular time
appdelegate instance
appdelegate instance  Hi, How to get appdelegate instance in some other part of the application? Thanks   Hi, Following code can be used to get the instance of Appdelete. MyAppDelegate *appDelegate = (MyAppDelegate
instance variables - Java Beginners
instance variables  instance variables
about instance of java
, An Instance creates the reference of an object. An object is a run time entity of the class. Difference: An instance refers to the copy of the object while...about instance of java  1> what is an instance 2> what
What are instance variables?
(instances of the class).Hence these variables are also known as instance variables...What are instance variables?   Hi, What are instance variables? thanks   Hi, Each object of the class has its own set of values
export instance sql
export instance sql  How to export instance in sql
Hibernate instance states.
Hibernate instance states.  Explain the types of Hibernate instance states
How to Create Instance using PHP
How to Create Instance using PHP  Hi, How to create an instance class in PHP program. Can someone explain or suggest any online reference how to create an Instance class in PHP. Thanks
static & instance - Java Beginners
static & instance  what is different between static variable and instance variable .? plz explain with example. and when we can use static variable and when can use instance variable.    public class Main
add a property to instance variable
add a property to instance variable  How to add a property to instance variable in iPhone SDK
Static & Instance variables in java
Static & Instance variables in java  What are the Difference between Static & Instance variables in java
unrecognized selector sent to instance
in xcode. unrecognized selector sent to instance   This kind
No action instance for path
No action instance for path  <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org.... * */ public class StrutsUploadAndSaveAction extends Action
creating instance of table in jsp
creating instance of table in jsp  i face senario look kie as follows; 1)i write a code in jsp to retrieve the data from database. 2)the out put... to make the instance of the data present in that paarticular table.... how i do
Object reference not set to an instance of an object
Object reference not set to an instance of an object  Object reference not set to an instance of an object
Explain instance in java - Java Interview Questions
Explain instance in java  Hi Friends, can you explain instance in java. In general instance means "occurence of something" . In java what is instance
Hibernate Creating criteria instance
Hibernate Creating criteria instance In this section you will learn about the creating of criteria instance in Hibernate. An instance of Criteria is created... a POJO/Persistent class to persist the objects here I have created
Difference between object and instance? - Java Beginners
Difference between object and instance?  What is the difference between object and instance in java
Class
are the basic run time entity or in other words object is a instance of a class... one it's own constructort. Constructor creates a instance for the class... to instance variables of the class. A default constructor with no arguments
class
class  Is a class a subclass of itself
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
Advertisements
 

 

 

DMCA.com