May 16, 2008 at 6:30 PM
Hi
class A {
int i, j;
}
class B {
int i, j;
}
class C extends A {
int k;
}
class D extends A {
int k;
}
public class ins {
public static void main(String args[]) {
A a = new A();
B b = new B();
C c = new C();
D d = new D();
if(a instanceof A)
System.out.println("a is instance of A");
if(b instanceof B)
System.out.println("b is instance of B");
if(c instanceof C)
System.out.println("c is instance of C");
if(c instanceof A)
System.out.println("c can be cast to A");
if(a instanceof C)
System.out.println("a can be cast to C");
System.out.println();
// compare types of derived types
A object;
object = d; // A reference to d
System.out.println("object now refers to d");
if(object instanceof D)
System.out.println("object is instance of D");
System.out.println();
object = c; // A reference to c
System.out.println("object now refers to c");
if(object instanceof D)
System.out.println("object can be cast to D");
else
System.out.println("object cannot be cast to D");
if(object instanceof A)
System.out.println("object can be cast to A");
System.out.println();
}
}
------------------------------------------
Read for more information.
http://www.roseindia.net/java/beginners/nonstaticvariable.shtml
Related Tutorials/Questions & Answers:
Java experts.Please answer this question - Java BeginnersJava experts.Please answer this question class A
{
void get()
{
System.out.println("A's method");
}
}
class C extends A{}
class D extends...();
}
}
------------------------------------------
Read for more information.
http://www.roseindia.net/
java Advertisements
Clarify my last question's answer - Java BeginnersClarify my last
question's answer Dear expert,
I've tried out... did not specify my
question too clearly.
Here's my 2 database...
question. Do you want to search through id or through the qualification selected
share your answer to this questionshare your
answer to this question i need to know what is the TELERIK CONTROL?
what is the map suite?
what is dunda chart?
Also i have to know what are the websites available which give infor regarding this.
Let me know how
pls answer these questionpls
answer these question Write a program that prompts the user to input the length and width of a rectangle.
Then calculate and prints the rectangleâ??s area and perimeter.
import java.io.*;
class rectangle
i cNT GET ANSWER FOR THIS QUESTIONi cNT GET
ANSWER FOR THIS QUESTION The roots of the quadratic equation ax2+bx+c=0, aïâ??¹0 are given by the following formula:
x=(-bÃ?±âË?Å¡(b^2-4ac))/2a
In this formula. The term b2-4ac is called
Plz answer - Java BeginnersPlz answer Create a
Java Bean Class â?? Customer according to the below given class diagram.
Customer
------------------------------------
- customerId : int
- customerName : String
- customerAddress : String
- pincode
Core Java Interview Question, Interview Question_TO_REPLACE_3
Question: How are
Java source code files named?
Answer: A
Java source code...
Core
Java Interview
Question Page 16
...?
Answer: Frame ADS_TO_REPLACE_1
Question: How are commas used
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 15
..., or TextComponent
Question: What is the GregorianCalendar class?
Answer... and redisplayed?
Answer: validate()
Question:
What is the purpose of the Runtime class
Core Java Interview Question Page 1
Core
Java Interview
Question Page 1
Question:
How could
Java classes... and the method sleep() is defined in the class Thread.
Question:
Can you write a
Java Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 17
... calendar.
Question: What is the Map interface? ADS_TO_REPLACE_8
Answer: The Map... with values.
Question: Does a class inherit the constructors of its
superclass?
Answer Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 2
... of this method?
Answer: It's possible if these variables are final.
Question: What can... the main difference between a Vector and an ArrayList
Answer:
Java Vector class
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 21
... to the Throwable type.
Question: What are E and PI? ADS_TO_REPLACE_4
Answer: E..._TO_REPLACE_5
Question: What is a void return type?
Answer: A void return type
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 30
...
Question: What happens when a constructor of the subclass is called
Answer...
Answer:
To reference it you will have to use OuterClass$InnerClass
Question: Can
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 19
... file system.
Question: Can an exception be rethrown?
Answer: Yes, an exception... button?
Answer: By associating Checkbox objects with a CheckboxGroup.
Question Question in Java ??Question in
Java ?? Welcome every One ,I have
Q in
Java :
Write aprogram that print the falewing table using SQRT method in the Math Class?
Number
0 ,2,
.
.
.
,18,20
squrfoot
00000
1.4142
5.2426
5.4721
Question in Java ?? Question in
Java ?? Welcome every One ,I have
Q in
Java :
Write aprogram that print the falewing table using SQRT method in the Math Class?
Number squrfoot
Question in Java ??Question in
Java ?? Welcome every One ,I have
Q in
Java :
Write aprogram that print the falewing table using SQRT method in the Math Class?
Number
0 ,2,
.
.
.
,18,20
squrfoot
00000
1.4142
5.2426
5.4721
java related questionjava related question How can we make a program in which we make mcqs
question file and then make its corresponding
answer sheet....like if we make 15 mcqs then
java should generate it
answer sheet of 15 mcqs with a,b,c d
Java Class Question?Java Class
Question? 1.
Create an application names Numbers whose... but not display the
answer instead it should return the
answer to the calling method which displays the
answer Question on javaQuestion on java why
java is not purely oop?
java is not purely OOP because
1.) Multiple Inheritance is not supported.ADS_TO_REPLACE_1
2.) It uses primitive data type.
3.) static method can be called without
Question Java>?Question Java>? **ïâ??· Create a new class called Bank and in the main method use class Account (lab 4) to create an array of 10 accounts.
ïâ??· Enter data for all accounts (account number,name, balance).
ïâ??· Add
Question Answer. If proper
answer is not given you can ask
question
detailing about the previous...
Question-
Answer Guidelines...
Here, you can post your desired
question. For
posting any
question / query
java question java question Create a class called Complex to perform arithmetic operations with complex numbers.
1- Use double variables to represent the fields of the class.
2- Provide a no-argument constructor with default values in case
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 23
... group. ADS_TO_REPLACE_3
Question: What is a
Java package and how is it used... that are loaded by a
Java program. ADS_TO_REPLACE_5
Question: How does a try statement
java questionjava question Implement a class called ShortAddress that has the following attributes: firstName, secondName, and phoneNumber.
Now implement... details or the long address details. This means your final
answer should have
java question :)java question :) write
java program to use vector in ArrayList with add, remove,sort
import java.util.Vector;
public class... Element MUAYAD");
vc.add("Vector Element
JAVA");
vc.add("Vector Element
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 28
...
Casting of object references
Question: When can conversion happen
Answer....
Question:
What are the rules for Object reference casting
Answer:
Casting
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 4
... and Unchecked Exceptions in
Java ?
Answer: All predefined exceptions in
Java... | +------------------+ / | | \ \_________________/ unchecked
Question: Explain garbage collection ?
Answer: Garbage
Core Java Interview Question, Interview Question
Core
Java Interview
Question Page 9
... to make a
java program as multithred
java program?
Answer: There are two ways... is in ?
Answer: Prior to
Java 5, isAlive() was commonly used to test a threads state