ROHIT CHOPRA
Java experts.Please answer this question
2 Answer(s)      7 years ago
Posted in : Java Beginners
Advertisement
View Answers

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





July 24, 2013 at 2:04 AM


package UI;

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Paint;
import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;

public class MainUI extends JDialog implements MouseListener {


    /**
     * @param args
     */

    static String[][] templocations=new String[5][];
    static int check1,check2,check3,check4,check5;
    ImageIcon imgicon;
    Image img;
    static JButton butt;
    JLabel addlabel,configure,exit;
    static Container con;
    EnlargeUI largeUI;
    static int count=0;
    static File savelocations = new File("e:\\Dock\\ObjectDock.doc");
    static File savealwaysonTop = new File("e:\\Dock\\alwaysonTop.doc");
    AddFrame temp=new AddFrame(this);
    static String checkTop="";

    public MainUI(){
        con = getContentPane();

        try{
            CreateButton button=new CreateButton("","",this);
            setUndecorated(true);
            setBounds(0, 0, 500, 65);
            setLayout(null);

            try {
                if(!savelocations.exists()){
                    savelocations.createNewFile();
                    // TODO Auto-generated catch block
                }
                if(!savealwaysonTop.exists()){
                    savealwaysonTop.createNewFile();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                Scanner scanFile=new Scanner(savelocations);
                while(scanFile.hasNext()){
                    String[] splitLocations=scanFile.nextLine().split(";");
                    AddFrame.GetID.setText(splitLocations[0]);
                    templocations[Integer.parseInt(splitLocations[0])-1]=new String[2];
                    templocations[Integer.parseInt(splitLocations[0])-1][0]=splitLocations[1];
                    templocations[Integer.parseInt(splitLocations[0])-1][1]=splitLocations[2];
                    AddFrame.GetPath.setText(splitLocations[1]);
                    AddFrame.GetTarget.setText(splitLocations[2]);
                    System.out.println(splitLocations[0]);

                    AddFrame.addShortCuts();
                }
                scanFile.close();
                Scanner scanFile1=new Scanner(savealwaysonTop);
                while(scanFile1.hasNext()){
                    checkTop=scanFile1.nextLine();
                }
                if(checkTop.equalsIgnoreCase("True")){
                    ConfigureUI.alwaysonTop.setSelected(true);
                }else{
                    ConfigureUI.alwaysonTop.setSelected(false);
                }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            addlabel = new JLabel("ADD");
            addlabel.setBounds(400, 5, 50, 25);
            addlabel.addMouseListener(this);

            configure = new JLabel("CONFIGURE");
            configure.setBounds(400, 20, 70, 25);
            configure.addMouseListener(this);

            exit = new JLabel("EXIT");
            exit.setBounds(400, 35, 50, 25);
            exit.addMouseListener(this);

            con.add(addlabel);
            con.add(configure);
            con.add(exit);

            setVisible(true);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new MainUI();

    }


    public void mouseClicked(MouseEvent arg0) {
        // TODO Auto-generated method stub
        if(arg0.getSource()==addlabel){
            AddFrame add = new AddFrame(this);
            add.setVisible(true);
        }else if(arg0.getSource()==exit){
            try {
                FileWriter writetoFile = new FileWriter(savelocations);
                for (int i = 0; i < templocations.length; i++) {
                    if(templocations[i]!=null && !templocations[i][0].equals("")){
                        writetoFile.write((i+1)+";"+templocations[i][0]+";"+templocations[i][1]+"\n");
                    }
                }
                writetoFile.flush();
                writetoFile.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.exit(0);
        }else if(arg0.getSource()==configure){
            ConfigureUI confi=new ConfigureUI(this);
            if(ConfigureUI.Y==1){
                confi.setBounds(arg0.getXOnScreen(), arg0.getYOnScreen()-130, 130, 200);
            }else{
                confi.setBounds(arg0.getXOnScreen(), arg0.getYOnScreen(), 130, 200);
            }
            confi.setVisible(true);
        }
    }


    public void mouseEntered(MouseEvent arg0) {
        // TODO Auto-generated method stub
    }


    public void mouseExited(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }


    public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }


    public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub
        //      largeUI.setVisible(false);
    }
}









Related Tutorials/Questions & Answers:
Java experts.Please answer this question - Java Beginners
Java 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
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
Advertisements
Clarify my last question's answer - Java Beginners
Clarify 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 question
share 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 question
pls 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 QUESTION
i 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
Please , can any one answer this Question?
Please , can any one answer this Question?  How to cummunicate one web application to another web application in different places
Plz answer - Java Beginners
Plz answer  Create a Java Bean Class ?? Customer according to the below given class diagram. Customer ------------------------------------ - customerId : int - customerName : String - customerAddress : String - pincode
i need to answer this Question but i can't do it probably
i need to answer this Question but i can't do it probably   use the web to locate the lyrics to the traditional song"The Twelve Days of Christmas" the song contains a list of gifts received for the holiday.the list is cumulative
hi,i'am new to Jsp.Can some one please let me know an answer for this question?
hi,i'am new to Jsp.Can some one please let me know an answer for this question?  how do we upload an xml file and validate them against WIPO DTD
Interview question link - Java Beginners
Interview question link  Hi, I want JAVA+J2EE interview question and answer please suggesion me link
plz. answer my ques - Java Beginners
plz. answer my ques  I want to ask a prog. prob which would create a prog that would simply take username and password as input and will display ***** while taking passwords as input.(As it is done at login in websites). Also
Core Java Interview Question Page 1
. Question: Explain the usage of Java packages. Answer: This is a way to organize... Core Java Interview Question Page 1       Question: How could Java classes
Core Java Interview Question, Interview Question
Core Java Interview Question Page 14       Question: What is clipping? Answer: Clipping... that is implemented in a language other than Java. Question: Can a for statement loop
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
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
Core Java Interview Question, Interview Question
Core Java Interview Question Page 17  .... Question: Can an object be garbage collected while it is still reachable? Answer... : z ? Answer: It is written x ? y : z. Question: What is the difference between
Core Java Interview Question, Interview Question
Core Java Interview Question Page 21  ... and are laid out using the squares of a grid. Question: What an I/O filter? Answer: An I.... Question: If an object is garbage collected, can it become reachable again? Answer
Question on java
Question on java  why java is not purely oop?   java is not purely OOP because 1.) Multiple Inheritance is not supported. 2.) It uses primitive data type. 3.) static method can be called without creating instances
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
website. If you found the question you can read the answer if it solves your...? Browse Latest Questions 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 22       Question: What is a compilation unit? Answer: A compilation unit is a Java source code file. Question: What interface
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 27  ... Question: Explain modifier final Answer: Final can be applied... and methods Question: Can abstract class be instantiated Answer
Core Java Interview Question, Interview Question
Core Java Interview Question Page 26  .... Which primitive datatypes are signed. Answer: All except char and Boolean Question.... It range is 0 to 2^7-1 Question: What forms an integral literal can be Answer
java question
java 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 related question
java 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
Core Java Interview Question, Interview Question
Core Java Interview Question Page 12       Question: What is a transient variable? Answer.... Question: How are Observer and Observable used? Answer: Objects that subclass
Core Java Interview Question, Interview Question
Core Java Interview Question Page 18       Question: Is &&= a valid Java operator? Answer: No, it is not. Question: Name the eight primitive Java