1 Answer - Sort by: Date | Rating
Well I am not clear with your Question
I suppose you want to know the instance of a class in java. I am guessing so...
public class InstanceDemo {
int no1; //class data member of type int
int no2; //also called as 'field' of type int in java
String tmp; //class data memberof type String
//Constructor
public InstanceDemo(int no1, int no2, String tmp) {
this.no1 = no1;
this.no2 = no2;
this.tmp = tmp;
}
public void display() {
System.out.printl name : " + this);
System.out.printl name : " + this.getClass());
System.out.printl />
System.out.printl : " + no1 + " *** and *** " + "no2 : "+ no2);
// this reference can also be used for a clear idea
System.out.printl : " + this.tmp);
System.out.printl /> }
public static void main(String[] args) {
//creating object
//here instanceDemo is an Instance of class InstanceDemo
//instance simply means Object of a class
InstanceDemo instanceDemo1 = new InstanceDemo(10, 20, "Hello");
InstanceDemo instanceDemo2 = new InstanceDemo(20, 30, "World!");
//we can create as many instance's as we wish
//but always remember each instance will have it's own copy of fields
instanceDemo1.display();
instanceDemo2.display();
}
}
I suppose you want to know the instance of a class in java. I am guessing so...
public class InstanceDemo {
int no1; //class data member of type int
int no2; //also called as 'field' of type int in java
String tmp; //class data memberof type String
//Constructor
public InstanceDemo(int no1, int no2, String tmp) {
this.no1 = no1;
this.no2 = no2;
this.tmp = tmp;
}
public void display() {
System.out.printl name : " + this);
System.out.printl name : " + this.getClass());
System.out.printl />
System.out.printl : " + no1 + " *** and *** " + "no2 : "+ no2);
// this reference can also be used for a clear idea
System.out.printl : " + this.tmp);
System.out.printl /> }
public static void main(String[] args) {
//creating object
//here instanceDemo is an Instance of class InstanceDemo
//instance simply means Object of a class
InstanceDemo instanceDemo1 = new InstanceDemo(10, 20, "Hello");
InstanceDemo instanceDemo2 = new InstanceDemo(20, 30, "World!");
//we can create as many instance's as we wish
//but always remember each instance will have it's own copy of fields
instanceDemo1.display();
instanceDemo2.display();
}
}
1
0
Where did my java code vanish???
Correct statements :
Public void display() {
System.out.println("Instance name : " + this);
System.out.println("class name : " + this.getClass());
System.out.println();
System.out.println("no1 : " + no1 + " *** and *** " + "no2 : "+ no2);
// this reference can also be used for a clear idea
System.out.println("tmp : " + this.tmp);
System.out.println();
}
Correct statements :
Public void display() {
System.out.println("Instance name : " + this);
System.out.println("class name : " + this.getClass());
System.out.println();
System.out.println("no1 : " + no1 + " *** and *** " + "no2 : "+ no2);
// this reference can also be used for a clear idea
System.out.println("tmp : " + this.tmp);
System.out.println();
}
- Do I Have To Write A Main Method In Every Class I Create?Why?
- Do I Have To Write A Main Method In Every Class I Create?
- What How The Step For Make Library Management?
- In Which Process We Can Start Java?
- Define The Concept Of Java Byte Code?
- How To Run Remote Method Invocation In More Machine?
- How To Run Java Remote Method Invocation In More Machine?
- How To Make A Java Program That Will Ask The User To Input A Number And Display All The Even Number And The Sum Of All Even Numbers Based On The Inputted/ Given Numbers?
- Is A Static Variable An Instance?
- How To Compile And Run Java Package?
- What Does Literati-on Mean?
- What Is Abstract Class In Details?
- What Is Meant By Remote Method Invocation In Java?
- What Is Meant By Package In Java?
- What Is Meant By Servlet In Java?
- When Was Java Released?
- What Is Latest Technologies In Java?
- Write A Program Using Do…..while Loop To Calculate And Print The First M Fibonacci Numbers?
- What Is The Difference Between Reference &instance Variable?
- Why Java Is Slow?
- What Is The Drawback Of Ms Access?
- What Is Replaced In Place Of Pointers In Java?
- What Replaces Pointers In Java?
- How Many Types We Create Object In Java?
- I Signed Up Promo Code 505124 For 12 Months My Bill Said For 6 Months Who Fix This Error?
- Can You Give The Sample Program In Java?
- Can You Give Me A Simple Java Program?
- How To Give Input In Java Program?
- What Is Implementation Inheritance In Java? Please Give An Example Program Also.
- What Is The Use Of Instance Variable In Java?
- What Is 'Instance Of' Operator In Java?
- What Is The Difference Between An Object And An Instance In Java?
- How Can We Run Java Program By Command Prompt? Give Answer In Steps Please?
- What Is The Difference Between Reference, Instance And Object In Java?
- How We Can Run The Program Of C++ In Java....?

New Comment - Comments are editable for 5 min.