About "method", "instance variable" and "constructor"

Does a method need to be initialise?? if yes, how to write the code?
for example,is it:
public String mymethod( String args[]); ?
public double mymethod2 (); ?
what is the meaning of "instance variable" and "constructor"?
Please help.....THANKS!

Previously posted to this OP:
Read the Java Tutorial: Learning the Java Language.
http://java.sun.com/docs/books/tutorial/java/index.html
� {�                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Error with instance variable and constructor of base class

    I am getting the error on the following statement "protected Point apoint" of by base class. What is causing this problem? See my code:
    package Shapes;
    public abstract class Shapes
         protected Point apoint; / ****error at this line****/
         public void move(double xdelta, double ydelta)
              apoint.x += xdelta;
              apoint.y += ydelta;
    public abstract void distance();
    public abstract void show();
    public String toString()
    return "\nThe starting point is at coordinates ("+x+","+y+")";
    package Shapes;
    public class Lines extends Shapes
    protected Point start;
    protected Point end;
         protected double x;
         protected double y;
         double delta;
         public Lines( final Point apoint, final Point bpoint)
    start.x = apoint.x;
              start.y = apoint.y;
              end.x = bpoint.x;
              end.y = bpoint.y;
    public Lines(double xstart, double ystart, double xend, double yend)
    this.xstart = xstart;
              this.ystart = ystart;
              this.xend = xend;
              this.yend = yend;
         public Lines(double x, double y)
              this.x = x;
              this.y = y;
                   public void distance(final Lines start, final Lines end)
                        delta = abs(Math.sqrt (super.x - start.x) * (super.x - end.x) +
                        (super.y - start.y) * (super.y - end.y));
                   Lines move(Point start, double delta)
                        end.x += delta;
                        end.y += delta;
                        return new Point(end);
    public Lines show()
    g.drawLine( start.x, start.y, end.x, end.y);
    public String toString()
    return super.toString()+ "\n moved distance is("
                   + start + ") : (" + end + ")"
                   +" \n to position(" + start + " ) : (" + end + ")";
    package Shapes;
    public class Rectangle extends Lines
         double delta;
    public Rectangle (Point top_lft_pt, Point bottom_rght_pt)
    super(top_lft_pt, bottom_rght_pt);
    public Rectangle(double x_top_lft, double y_top_lft, double x_bottom_rght, double y_bottom_rght)
    super(x_top_lft, y_top_lft, x_bottom_rght, y_bottom_rght);
         public Rectantgle is_it_diagonal()
              if(top_lft.x > bottom_rght.x && bottom_rght.x < top_lft.x)
                   System.out.println("Point are Not Diagonal");
                   public void distance(double delta)
                        delta = abs(Math.sqrt (top_lft.x - bottom_rght.x) * (top_lft.x - botton_rght.x) +
                        (top_lft.y - bottom_rght.y) * (top_lft.y - bottom_rght.y));
                   public Rectangle move(final Point top_lft_pt, double delta)
                        bottom_rght.x += delta;
                        bottom_rght.y += delta;
                        return new Point(bottom_rght_pt);
                   public void get_top_rght_coords()
                        Point top_rght = new Point();
                        top_rght.x = bottom_rght.x;
                        top_rght.y = top_lft.y;
                   public void get_bottom_left_coords()
                        Point bottom_lft = new Point();
                        bottom_lft.x = top_lft.x;
                        bottom_lft.y = bottom_rght.y;
         public Rectangle show()
                        g.drawLine(top_lft.x, top_lft.y, top_rght_x, top_rght_y);
                        g.drawLine(bottom_lft.x, bottom_lft.y, bottom_rght.x, bottom_rght.y);
                        g.drawLine(top_lft.x, top_lft.y, bottom_lft.x, bottom_lft.y);
                        g.drawLine(top_rght.x, top_rght.y, bottom_rght.x, bottom_rght.y);
    package Shapes;
    public class Circles extends Lines
    protected double radius;
         public double delta;
         protected Point center;
    public Circles(double x, double y, double radians)
    super(x, y);
              radius = radians;
         public Circles(Point acenter)
              center.x = acenter.x;
              center.y = acenter.y;
    public void distance()
    delta = abs(Math.sqrt(super.x - x) * (super.x - x) + (super.y - y) * (super.y -y));
         public Circles move(final Point Circles, double delta)
              return new Point(Circles);
    public void show()
    g.drawOval(Circles.x, Circles.y, radius, radius);
    package Shapes;
    import java .math .*;
    import java.util .Random ;
    public class ShapesDriver
    Shapes[] aShape = new Shapes[10];
    static double range = 101.0;
    static Random r1 = new Random();
    public static void main(String [] args)
    double[][] coords = new double[10][10];
    double[] radians = new double [10];
    Shapes anyShape = {
    new Circles(radians),
    new Lines(coords),
    new Rectangle(coords)
    Shapes aShape; /***error at this line***/
              for(int i = 1; i <= coords.length; i++)
    for(int j = 1; j <= coords.length; j++)
                                                      coords[i][j] = r1.nextDouble () * range;
                                                      radians[j] = r1.nextDouble () * range;
    aShape[i] = anyShape[r1.nextInt(aShape.length)];
    System.exit(1);

    Thanks for your help with this problem. Now I have another problem that I am having a hard time figuring out. My program is using inheritance and polymorphism. I trying to use only one version of methods in the superclass points which extends the shapes class which is the abstract superclass vs. repeating the implementation of the methods (move, show, etc.) in each of the subclasses. The error I am getting is this "declare the class abstract, or implement abstract member 'Point Shapes.move()'. As you see, move is declared abstract and of type point in the Shapes superclass and it's behavior is implemented in the subclass Points extending Shapes. The other subclasses, circle, rectangle and lines will invoke the move method from Points and return a new point object. Why I am I getting the error to declare or implement move when the implementation is in Point?
    Below is code, please help?
    import java .awt .Point ;
    public class ShapesDriver
         public static void main(String args[])
              int count = 0;
              int choice;
              Point start = null;
              Point end = null;
              System.out .println(" 1 i am here");
              start = new Point((int)(Math.random()* 10.0), (int)(Math.random()* 10.0));
              end = new Point((int)(Math.random()* 10.0), (int)(Math.random()* 10.0));
         System.out .println(" 2 i am here");     
         System.out.println (start);
         System.out.println(end);                         
         for(int i = 0; i <= count; i++)
              System.out .println(" 3 i am here");
              choice = (int)(4.0 * Math.random());
              System.out .println(" 4 i am here");
              System.out.println (choice);     
         switch(choice)
              case 0: //Lines
              System.out .println(" 5 i am here");
              Lines apoint = new Lines((int)(Math.random()* 10.0), (int)(Math.random()* 10.0),
                                  (int)(Math.random()* 10.0), (int)(Math.random()* 10.0));
              Point coords = new Point((int)(Math.random()* 10.0),
                             (int)(Math.random()* 10.0));
              new Point((int)(Math.random()* 10.0),
                             (int)(Math.random()* 10.0));
              break;
              case 1: //Circles
              System.out .println(" 6 i am here");
              Circles center = new Circles((double)(Math.random()* 10.0),
              (double)(Math.random()* 10.0), (double)(Math.random()* 10.0),
              (double)(Math.random()* 10.0),(double)(Math.random()* 10.0));
              Circles centerpt = new Circles((int)(Math.random()* 10.0),
              (int)(Math.random()* 10.0), (int)(Math.random()* 10.0),
              (int)(Math.random()* 10.0), (double)(Math.random()* 10.0));
         break;
              case 2: //Rectangles
         System.out .println(" 7 i am here");
              Rectangle top_lft_pt = new Rectangle ((double)(Math.random()* 10.0),
                             (double)(Math.random()* 10.0), (double)(Math.random()* 10.0),
                             (double)(Math.random()* 10.0), (double)(Math.random()* 10.0),
                             (double)(Math.random()* 10.0));
              Rectangle bottom_rgt_pt = new Rectangle ((double)(Math.random()* 10.0),
                   (double)(Math.random()* 10.0), (int)(Math.random()* 10.0),
                             (int)(Math.random()* 10.0), (int)(Math.random()* 10.0),
                             (int)(Math.random()* 10.0));
         break;
         default:
         System.out .println(" 9 i am here");
         System.out.println("\nInvalid shape choice =" + choice);
         System.exit(0);
         break;
         try
                   System.in.read();
                   catch(java.io.IOException ioe)
    import java .awt .Point ;
    public abstract class Shapes
         private String shape;
         public Shapes(String ashape)
              shape = new String(ashape);
         public abstract Point move();
         public double distance()
              return 0.0;
         public abstract void show();
         public String toString()
              return "\nThis shape is a" + shape;
    import java .awt .Point ;
    public class Rectangle extends Points
         protected Point top_lft;
         protected Point top_rgt;
         protected Point bottom_lft;
         protected double top_lft_x;
         protected double top_lft_y;
         protected double bottom_rgt_x;
         protected double bottom_rgt_y;
         protected Point bottom_rgt;
         protected double delta = 0;
         protected String shape = "Rectangle";
         public Rectangle(double x, double y, double top_lft_x,
                             double top_lft_y, double bottom_rgt_x,
                             double bottom_rgt_y)
              super(x, y);
              top_lft_x = top_lft_x;
              top_lft_y = top_lft_y;
              bottom_rgt_x = bottom_rgt_x;
              bottom_rgt_y = bottom_rgt_y;
         public Rectangle( double x, double y, Point bottom_rgt, Point top_lft)
              super(x, y);
              bottom_rgt_x = bottom_rgt.x;
              bottom_rgt_y = bottom_rgt.y;
              top_lft_x = top_lft.x;
              top_lft_y = top_lft.y;
         public String toString()
              return super.toString() + " coordinates top left= " + top_lft_x + "," + top_lft_y + "and bottom right" +
                   bottom_rgt_x + "," + bottom_rgt_y + ")";
         public void is_it_diagonal()
              if(top_lft_x < bottom_rgt_x && bottom_rgt_x > top_lft_x)
                   System.out.println("Points are Not Diagonal");
              public double distance()
                   distance ();
                   return delta;
              public Point move(Point top_lft)
                   move();
                   bottom_rgt_x += delta;
                   bottom_rgt_y += delta;
                   return top_lft;
              public void get_other_coords()
                   top_rgt.x = bottom_rgt.x;
              top_rgt.y = top_lft.y;
                   bottom_lft.x = top_lft.x;
                   bottom_lft.y = bottom_rgt.y;
              public void show()
                   super.show();
                   System.out.println("new coords are :");
                   System.out .println ("(" + top_lft_x + "," + top_lft_y + ")");
                   System.out .println ("top right(" + top_rgt + ")");
                   System.out .println ("(" + bottom_rgt_x + "," + bottom_rgt_y + ")");
                   System.out .println ("bottom right(" + bottom_rgt + ")");
    import java .awt .Point ;
    public class Points extends Shapes
         protected double delta = 0.0;
         protected double x;
         protected double y;
         protected String ashape = "Points";
         public Points( double x, double y)
              super("Points");
              x = x;
              y = y;
         public Points( Point start)
              super("Points");
              x = start.x;
              y = start.y;          
         public String toString()
              return super.toString() + "References coordinates(" + x + y + ")";
         public double distance(double x1, double y1 )
              return delta =(Math.sqrt(x - x1) * (x - x1) + (y - y1) *
              (y - y1));
         public Point move(Point pts)
              pts.x += delta;
              pts.y += delta;
              return pts;
         public void show()
              System.out.println("This shape is a" + ashape + "(" +
                                  "(" + x+ "," + y + ")");
    import java .awt .Point ;
    public class Lines extends Points
         double delta = 0;
         protected double x;
         protected double y;
         protected String ashape = "Lines";
         public Lines( double x1, double y1, double x, double y)
              super(x1,y1);
              x = x;
              y = y;
         public Lines(Point start, Point end)
              super(start);
              x = end.x;
              y = end.y;
         public String toString(Point end)
              return super.toString() + "line points = (" + x + "," + y +
                   "(" + end + ")";
         public double distance()
              distance ();
              return delta;
         public Point move(Point lines)
              move ();
              return lines;
         public void show()
              System.out.println("This shape is a" + ashape + "(" +
                                  "(" + x + "," + y + ")");
    import java .awt .Point ;
    public class Circles extends Points
    protected double radius;
    protected double xcenter;
    protected double ycenter;
    protected String ashape = "Circle";
         public Circles( double x, double y, double cx, double cy, double radians)
              super(x, y);
              xcenter = cx;
              ycenter = cy;
              radius = radians;
         public Circles( Point acenter, Point ref, double radians)
              super(ref);
              xcenter = acenter.x;
              ycenter = acenter.y;
              radius = radians;
         public String toString(Point ref)
              return super.toString() + " reference points (" +
                   ref + ")" +
                   "center coordinates (" + xcenter + "," + ycenter + ")";
              public double distance(Point ref)
                   return (Math.sqrt(ref.x - xcenter) * (ref.x - xcenter)
                             + (ref.y - ycenter) *
              (ref.y - ycenter));
              public Point move(Point center)
                   move();
                   return center;
              public void show()
                   System.out.println("This shape is a" + ashape + "(" +
                                  "(" + xcenter + "," + ycenter + ")");

  • Question about final instance variables

    Hi, I recently have come across a situation that I realized I did not understand and I could not find the answer after a bit of googling and searching the forum so I thought I would quickly pose the question to the crowd. Basically I want to know if declaring a final instance variable and assigning it to an existing Object will make an immutable copy of that Object. For example:
    Dimension myDims;
    public void someMethod()
    myDims = new Dimension(320, 240);
    doSomething();
    public void doSomething()
    final myFinalDims = myDims;
    This is not real code (obviously) and I made it quickly just to get my point across. Basically my question is if I create an Anonymous Inner class within the doSomething() method that accesses the myFinalDims variable, will the inner class actually access the myDims variable (which could have its value changed before the inner class accesses the variable) or will it be accessing a copy of the myDims Object that will have the same value as when the final variable was declared and instantiated?

    Basically I want to know if declaring
    a final instance variable and assigning it to an
    existing Object will make an immutable copy of that
    Object. Big no. It will neither make a copy, nor will anything be immutable. Final just means that once the value or reference of the attribute or variable is set, it can't be altered.
    final StringBuffer sb = new StringBuffer();
    sb.append("!");still works.
    Your inner class will access the instance of Dimensions stored in myDims. There won't be any other instance.

  • Jdev11 complains about public instance variables, but not Jdev10

    Hi all, if I fire up Jdeveloper10 I can declare a public instance variable. (OK, stylistically maybe not a good thing, but nothing in the java 'rules' that says I shouldn't be able to do this.) However in Jdeveloper11 it complains, it underlines it in red and grumbles "should not have greater than protected access."
    Anyone know where to turn off this compiler hint?
    thanks.
    public class Thing() {
    public String bob; // complains in jdev11, ok in jdev10.

    Hi Kevin, thanks for the tip. It's taken me years just to remember where to turn on the line numbers in 'preferences' , so I would never have found that one about the instance variable checks ! Frank, thanks for the update, I agree it's useful as a stylistic hint, but I think that the Jdev floating code assist, rather than just hinting "declare this field protected" (as this will obviously fix it) would be more user-friendly if it also said "or disable under preferences - code assists." But Jdev11 is growing on me, tons of cool stuff :-)
    thanks all.

  • What is the difference between Instance variable and Global variable?

    Hi folks,
    Could you please explain me, "what is the difference between Instance variable and Global variable?"
    Are they really same or not?
    --Subbu                                                                                                                                                                                                                                                                                                               

    Hi flounder,
    I too know that there is no such a term GLOBAL in java.
    generally people use to say a variable which is accessible throught out the class or file has global access
    and that will be called as a global variable...
    my point is very much similar to what Looce said.
    In simple that is not a technical term, but just a causual term.
    In technically my question is, "What is the difference between a instance variable and public variable?".
    Hi looce,
    Thanks for the reply. even thats what my understanding too....in order to confirm that i raised this question..
    Your reply has given a clear answer...... thanks again.
    --Subbu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • What is the difference between instance variable and class variable?

    i've looked it up on a few pages and i'm still struggling a bit maybe one of you guys could "dumb" it down for me or give and example of how their uses differ.
    thanks a lot

    Instance is variable, class is an object.What? "Instance" doesn't necessarily refer to variables, and although it's true that instances of Class are objects, it's not clear if that's what you meant, or how it's relevant.
    if you declare one instance in a class that instance
    should be sharing within that class only.Sharing with what? Non-static fields are not shared at all. Sharing which instance? What are you talking about?
    if you declare one class object it will share
    anywhere in the current program.Err...you can create global variables in Java, more or less, by making them static fields. If that's what you meant. It's not a very good practice though.
    Static fields, methods, and classes are not necessarily object types. One can have a static primitive field.

  • How to change value of instance variable and local variable at run time?

    As we can change value at run time using debug mode of Eclipse. I want to do this by using a standalone prgram from where I can change the value of a variable at runtime.
    Suppose I have a class, say employee like -
    class employee {
    public String name;
    employee(String name){
    this.name = name;
    public int showSalary(){
    int salary = 10000;
    return salary;
    public String showName()
    return name;
    i want to change the value of instance variable "name" and local variable "salary" from a stand alone program?
    My standalone program will not use employee class; i mean not creating any instance or extending it. This is being used by any other calss in project.
    Can someone tell me how to change these value?
    Please help
    Regards,
    Sujeet Sharma

    This is the tutorial You should interest in. According to 'name' field of the class, it's value can be change with reflection. I'm not sure if local variable ('salary') can be changed - rather not.

  • What's the difference between global variables and instance variables?

    hi im just a biginner,
    but what is the difference between these two?
    both i declare them above the constructor right.
    and both can access by any method in the class but my teacher said
    global variables are not permitted in java....
    but i don't know what that means....and i got started to confuse these two types,,
    im confusing.......
    and why my teacher said declaring global variables is not permitted,,,,,,
    why.....

    instance variables are kindof like Global variables. I'm not surprised you are confused.
    The difference is not in how they are declared, but rather in how they are used.
    There are two different "styles" of programming
    - procedural programming.
    - object oriented programming.
    Global variables are a term from Procedural programming.
    In this style of programming, you have only one class, and one "main" procedure. You only create one instance of the class, and then "run" it.
    There is one thread of control, which goes through various methods/procedures to accomplish your task.
    In this style of programming instance variables ARE "global" variables. They are accessible to all methods. There is only one instance of the class, and thus only one instance of the variables.
    Global variables are "bad" BECAUSE you can change them in any method you like. Even from places that shouldn't have to. Also if you use the same name as a global variable and a local variable, you can cause great trouble. This can lead to very subtle bugs, as the procedures interact in ways you don't expect.
    The preferred method in procedural programming is to pass the values as parameters to the methods, and only refer to the parameters, and local variables. This means that you can track exactly what your method is doing, and what it affects. It makes it simpler to understand. If you use global variables in your methods, it becomes harder to understand.
    So when are instance variables not global variables?
    When you are actually using the class as an Object, rather than just a program to run. If you are creating multiple instances of an object, all with different values for their instance variables, then they are not global variables. For instance you declare a Person object with an attribute "firstname". Your "main" program then creates many instances of the Person object, each with their own "firstname"
    I guess at the end of all this, it comes down to definitions.
    Certainly you can write procedural code in java. You can treat your instance variables, for all intents and purposes like global variables.
    I can only think to show a sort of example
    public class Test1
       User[] users;
       public void printUsers(){
         // loop through and print all the users
         // uses a global variable
          for(int i=0; i<users.length; i++){
            users.printUser();
    public void printUsers(User[] users){
    // preferred method - pass it the info it needs to do the job
    for(int i=0; i<users.length; i++){
    users[i].printUser();
    public Test1(){
    User u1 = new User("Tom", 20);
    User u2 = new User("Dick", 42);
    User u3 = new User("Harry", 69);
    users = new User[3];
    users[0] = u1;
    users[1] = u2;
    users[2] = u3;
    printUsers();
    printUsers(users);
    public static void main(String[] args)
    new Test1();
    class User{
    String firstName;
    int age;
    public User(String name, int age){
    this.firstName = name;
    this.age = age;
    public void printUser(){
    // here they are used as instance variables and not global variables
    System.out.println(firstName + " Age: " + age);
    Shit thats a lot of typing, and I'm not even sure I've explained it any good.
    Hope you can make some sense out of this drivel.
    Cheers,
    evnafets

  • Using 'variables.instance' structure and implicit getters/setters

    I am adopting the use of creating a variables.instance (I use 'variables.my') structure to separate instance data from the object, however I have a question when it comes to ColdFusion creating implicit getters and setters based on that object's defined properties.
    BEFORE, if I had a Name property, CF would create getName() and setName() for me, and it would update the variables.Name private variable accordingly in each.  But now that my variables are being stored in 'variables.my.Name', does this mean I can no longer use ColdFusion's implicit getters and setters? (because it would improperly be attempting to execute getName and be looking for variables.Name, when that data now exists in variables.my.Name?
    Are there any methodologies around that allow me to utilize CF's implicit getters/setters while using this 'my' instance variable and have them work with one another?

    Thanks for the confirmation Carl.
    How cool, then, would it be if ColdFusion 11 supported something like:
    <cfcomponent
         accessors="true"
         implicitpropertyprefix="my."
    That way I could specify "my." as the property prefix and when it goes to create those implicit getters and settings, it will concatenate that into 'variables.my.' as the prefix when it alters property values or returns them.

  • Servlet instance variables

    This might be a dumb question, but I'll ask it anyway...
    I have methods in my servlet to handle registration, specifically creating address, customer and order objects.
    All the information needed for creating my objects is coming from the registration form.
    Right now if I were to call the createAddress() method, I have to pass the request object.... createAddress(request);
    Would it be "thread safe" to make an instance variable of the request and refer to it using getters/setters? Or would it be wiser (and best practice) to make instance variables for the request attributes (like firstName, lastName, etc.)? Or am I way off and shouldn't be doing any of the above?
    Thanks for the help.

    GB_java_guy wrote:
    To answer you question, I think it's different, from what I've read, because request attributes are supposed to be thread safe and I'd be using the request attributes instead of the request object.You said something about "making instance variables for the request attributes." I don't know what you mean by that, but if it's instance variable in the servlet class, don't do it.
    I have no clue what you mean by "request attirbutes intead of request object."
    So are you saying I should just use the request object and pass that to my methods instead? In general, yes. In some cases you may want to pass individual pieces of it--e.g. if there's a method that doesn't need to know or care about the fact that you're operating in a servlet context, and just needs a couple values to do its job.

  • Renaming instance variable VS use of "this."

    Open Topic:
    Do you prefer this code?
    private var _myVar:int;
    public function myClassConstructor(value:int) {
         _myVar = value;
    or this code? (JAVA style)
    private var myVar:int;
    public function myClassConstructor(myVar:int) {
         this.myVar = myVar;
    Discuss the pros and cons, especially if performance is involved.
    You have 10 minutes... I will be collecting the papers

    Bertrand G. wrote:
    So no one is concerned about any performance issues using 'this'... I have seen somewhere that using 'this' in C++ is not as efficient as renaming the variable, because it makes an object instantiation or something like that.
    Most people will go for clarity of purpose in the code in preference to performance, simply because performance is not a critical factor for MOST purposes.
    I personally prefer using this for the setters and getters, this way I can have the same variable name for both the method parameters and the class variable.
    Just my 2 cents...
    I think the usual practice for getters and setters is to have a private variable for the instance variable and to name it with an underscore prefix to indicate that the variable is private. In that way references to the private variable are distinct to the variable name used in the setter and getter. In any event, in my setter I invariably name the parameter with the new value "newValue" or "newWhatever", some people just use "pWhatever" to indicate that variables have been passed as parameters, so the use of "this" is not required.
    I don't see the use of "this" as particularly relevant to performance, or getters and setters, and I would recommend naming private variables with an underscore prefix to indicate the use of a private instance variable, though not everyone follows this convention and may use other conventions, or indeed no convention at all.
    Paul

  • Inheritance - instance variable initialization

    Hi all.
    I have a question regarding inherited instance variables.
    class Animal {
       int weight;
       int age = 10;
    class Dog extends Animal {
       String name;
    class Test {
       public static void main(String[] args) {
          new Dog();
    }This is just an arbitrary code example.
    When new Dog() is invoked, I understand that it's instance variable "name" is give the default
    type value of null before Dog's default constructor's call to super() is invoked.But Im a little perplexed about
    Animals instance variables. I assume that like Dog, Animals instance variables are given their default type values
    of 0 & 0 respectively, before Animals invocation of super(); What im unclear about is that at the point that weight and age are given their default type values, are Dog's inherited weight and age variables set to 0 aswell at that exact moment? Or are Dog's inherited weight and age variables only assigned their values after Animals constructor fully completes because initialization values are only assigned to a classes instance variables after it's call to super().
    Many thanks & best regards.

    Boeing-737 wrote:
    calvino_ind wrote:
    Boeing-737 wrote:
    newark wrote:
    why not throw in some print statements and find out?Super() or this() have to be the very first statement in a constructor..
    Also you cannot access any instance variables until after super or this.
    :-S
    Kind regardsbut if you add the "print" statement in animal constructor, you can easily see what happened to the attributes of Dog ; that s the trick to print "before" super()You can never add a print before super(). It's a rule of thumb, super() and this() must always be the first statements
    in a constructor, whether added implicitly by the compiler or not. In this case there are 2 default constructors (inserted by the compiler), each with a super() invocation. Even if i added them myself and tried to print before super(), the compiler would complain.
    Thanks for the help & regards.you didn't understand what i meant ; take a look at that:
    class Animal {
       int weight;
       int age = 10;
       public Animal() {
           Dog thisAsADog = (Dog) this;
          System.out.println(thisAsADog.name);
          System.out.println(thisAsADog.x);
    class Dog extends Animal {
       String name;
       int x = 10;
    public class Test {
       public static void main(String[] args) {
          new Dog();
    }this way you will know what really does happen

  • Null Instance Variables on Screenflow

    Hi,
    I have some problems with instance variable of type BPM Objects in a Screenflow.
    I always create automatic processes without user interaction, and on server side I have seen that it's not necessary to instantiate an instance variable. Moreover if within a method I write (I use the Java style syntax):
    String a;
    a.toString(); // just to call a method on a not-instantiated variable
    everything works correctly, the "a" variable is automatically instantiated.
    But it seems that in an automatic activity of a Screenflow it's different, I need to do the new also for Instance Variables.
    Then, in the Screenflow I have an Instance Variable myObject of type MyObject that is a BPM Object. This object has an attribute myStrings that is an array of String.
    To instantiate the instance variable I can write:
    myObject = new MyObject();
    But then I get a java.lang.*NullPointerException* when I call the extend method of its attribute myStrings to add a string.
    Do you agree with me that on the Screenflow code it's necessary to instantiate the variables?
    How can I instantiate an Array of String?
    Thank you.

    Thanks Daniel, I'm using ALBPM 6.0,
    i know the line where I get the exception, I have a logMessage before and after each line of code, and then in the exception stack there is the PBL Method line indicated:
    Caused by: java.lang.NullPointerException
         at xobject.Fuego__AutoGen__Screenflows__.__ScreenflowConJsp.automatic1(__ScreenflowConJsp.xcdl:*19*)
    19 is the code line where I get the exception. In this line I have this:
    myObject.myStrings.extend(arg1 : a);
    but the null object is not the array, it's myObject that is an Instance Variable.
    In ALBPM60_Studio_ReferenceGuide at chapter Programming Styles paragraph Java Programming Style there is:
    This style emulates Java syntax and adds several features to match PBL expressions. These added features include:
    • Output arguments
    • Input and display statements
    • Variable auto-initialization
    In fact in my previuos BPM projects I have seen that is not necessary to istantiate the variables, both for Instance Variable and local variable declared within a method. In my previous post I did an example:
    String a;
    a.toString();
    Usually this causes an Exception, but not in ALBPM methods.
    My main question is: is it possible that this is true just for Server side methods and not for Screenflow methods? Because in my case I need to instantiate every Instance Variable of my Screenflow (for example the myObject instance variable) in an Automatic Activity I have put as first Activity of the flow.
    Thanks again for your help.

  • JDEVELOPER 10G, ADF BC: Passivate static instance variables in AM?

    I understand the need to passivate/activate instance variables but what about static instance variables within an application module?
    Thanks,
    Wes

    Static variables - being class variables and not instance variables - persist without a need for passivation. Is there a particular reason or scenario why to use static variables? You have to consider that since all AM instances will share it, changing it in one AM instance - i.e. one user session - will affect all other AM instances - i.e. all other user sessions! You also have to consider the implications of multithreading when attempting to modify the static variable.

  • Question about Hyperion Environmental Variables

    Hi,
    Can someone please give me a clear explanation about the following Environment variables in Hyperion. I am very much confused about these variables, it would be really helpful for me to understand better if I get a clear explanations of those.
    1) ARBORPATH
    2) ESSBASEPATH
    3) HYPERION_HOME
    4) ORACLE_HOME
    5)ORACLE_INSTANCE
    Thanks in advance!!!
    Regards,
    Newton

    Basically I want to know if declaring
    a final instance variable and assigning it to an
    existing Object will make an immutable copy of that
    Object. Big no. It will neither make a copy, nor will anything be immutable. Final just means that once the value or reference of the attribute or variable is set, it can't be altered.
    final StringBuffer sb = new StringBuffer();
    sb.append("!");still works.
    Your inner class will access the instance of Dimensions stored in myDims. There won't be any other instance.

Maybe you are looking for

  • Alarm clock problem and question

    My son is having problems with the alarm on his iPhone 3G. Sometimes it simply does not go off. He has tried resetting, it didn't help. I searched the forums and noticed that some other people have had the same problem. Perhaps the upcoming software

  • Best Methods for Time, Tempo and Rhythm Alignment?

    Hello All, I am looking to edit some lengthy jams to concise segments. I wish to mix and match audio tracks (ex. drum section from begining with bass section in middle with guitar section at end). No metronome was used, so while the general structure

  • Not able to Download Apps anymore.....

    Can't Download Apps anymore.... For about three weeks now, I have not been able to download apps from the market or any other site. I am able to scroll through the apps or scan the code, but when I click the install, I get this following message ever

  • OO Design Point

    I'm simulating a "University Registration System" webapp based on the Java Servlet Technology. There're main entities like Course, Student, CourseSection, Registration. CourseSection has a ( it's teacher ) Professor and a ( it's content ) Course refe

  • Camera does not show?

    Why doesn't Olympus FE 220 digital camera appear when trying to import pictures to iPhoto 6 on Imac OS 10.4.11? Thank you, Fasron