Setting final Instance variables in Child Classes

Hello:
Is it possible to declare (not initialize) a final variable in an abstract parent class and set it in a non-abstract child class.
An example for clarification.
I have an abstract parent class (call it P) and two child classes (call them (C1 and C2). There is common processing that goes on in P. This processing uses a variable called x. C1 will set x to equal 10 and C2 will set x to equal 20. Can I declare x final in the abstract class P and set it in C1 and C2
This is impossible right? I know some other languages allow this behavior so I just wanted to make sure that Java does not support it.
Thanks
Johnny

Why don't you just try it out? Though I'm pretty sure it won't work, as it should expect all constructors of the abstract class to set it. But you could either let there be an overridden method that returns the appropriate value for the sub-class:
abstract class P
  abstract protected int getTheValue();
class C1 extends P
  protected int getTheValue() { return 10; }
class C2 extends P
  protected int getTheValue() { return 20; }
}

Similar Messages

  • 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.

  • Setting process instance variable

    Hi,
    I've a process with a instance variable "dossierVar" of class Dossier.
    I've the following code to go through the existing processes :
    Fuego.Papi.BusinessProcess bp;
    bp.connectTo(url : Fuego.Server.directoryURL, user : "adminfonc", password : "agra2009",
    process : processName);
    Fuego.Papi.InstanceFilter instF = InstanceFilter();
    instF.create(processService : bp.processService);
    instF.searchScope = SearchScope(participantScope : ParticipantScope.ALL, statusScope : StatusScope.ONLY_INPROCESS);
    Fuego.Instance[] instances = bp.getInstancesByFilter(filter : instF);
    foreach (instance in instances) {
    I'd like to know how to set the variable "dossierVar" of these instances ?
    Thanks you for our help

    Hi,
    take a look in this post.
    Obtain an instance variable of one process from another process
    If your variable is not a separeted one, so this code works well in order to get the variables value.
    Thanks
    Marcos Chiodi Martins

  • Is it allowed to set bmp instance variables in ejbFindByPrimaryKey

    Hello together,
    one simple question to the specification gurus:
    Is it allowed to set the instance variables of a Bean Managed Persistence
    Entity Bean inside the ejbFindByPrimary Key method?
    The Problem is:
    We are using OC4J (Oracle Containers 4 J2EE) and run multi threaded clients.
    In some situations it happens, that the same instance of an Entity in "pooled state"
    is used for concurrent ejbFindByPrimaryKey calls by the container.
    Due to the implementation of the ejbFindByPrimaryKey it sometimes happens,
    that during this call the Threads are switched and the value returned by the
    method, which is stored into an instance variable, is overwritten (some typical
    unwanted side effect in a multithreaded environment).
    So this leads to the question above!
    Ciao
    Stefan

    As far as I'm aware you shouldn't attempt to change the state in an ejbFindByPrimaryKey method - this should simply look up the appropriate instance, not alter the state. ejbLoad seems a more appropriate place to be doing that sort of thing.
    I'm not too sure, though - obviously your application will have very particular requirements.

  • Seemingly unpredictable results when calling an overriden parent method on an instance of a child class casted to the parent class

    I have a parent class with a sub-vi Override.vi, and a child which overrides this sub-vi.  I create an instance of this child.  I cast this child to it's parent class and store it in an array.  Later, if I invoke the parent's 'Override.vi' on this child (casted to parent) then Labview 2013 seems to randomly choose whether to run the parent or the child override.vi.  In Labview 2011 SP1 it would always call the childs version of override.vi (which while surprising to me was very useful).  This has totally broken an application I have been developing, any insight as to how to control which override.vi is run would be helpful (re-casting to the child class isn't really an option, as there are in fact many child classes each with their own version of override.vi).

    The actual data type of the wire is irrelevant in deciding which VI to run. The only thing that is relevant is the class of the object which is actually on the wire, so casting to the parent should not be relevant. *IF* the object really is a child, then LV should always call the child's VI, just like you say it works in 2011.
    I suspect that what's happening in your case is that somewhere you're generating a parent and that's what's actually on the wire (e.g. maybe you have an error somewhere and a function outputs the default value, which is a parent). The fact that it didn't happen in 2011 doesn't mean it's a bug in 2013. It could be that something else has changed.
    In any case, it's impossible to tell whether this is a misunderstanding, a bug in your code or a bug in LV without actual code. If you can post actual code which shows this, people can help. Otherwise (if it only happens in code you don't want to publish), you should try contacting NI directly so that you can at least show them the code.
    Try to take over the world!

  • Loading the final static variables at run time.. Please help

    Hello, fellow developers & Gurus,
    Please help me figure out the best way to do this:
    I need to load all my constants at run time. These are the public static final instance variables. The variables values are in the DataBase. How do I go about loading them.

    Your original question was diffeent, but your further posts show what you really want to do:
    1) all constants in 1 class
    2) available readonly for other classes
    3) updatable during runtime by changing in the database
    Did I understand you right?
    Then smiths' approach solves point 2):
    Instead, make the variables available through a method
    call - that way you avoid the whole final variable
    versus read-only attributes problem.
    //GLOBAL VARIABLES EXPOSED AS PUBLIC PROPERTIES
    public final class GlobalProperties
    public static int getTableSize();
    public static int getRowSize();
    Each "constant" should be a private static variable, and these methods simply return their values.
    The variables are initialized in a static initializer by accessing the db. Ok.
    You habe a table with one row containing as columns all the constants.
    A method readConstants() does a "select constant1, constant2, ... from const_table" and sets all the variables.
    The static initializer calls this method.
    Right?
    Ok, then you simply call readConstants() everytime you want to synchronize with the actual content of const_table.
    Was it this?

  • Sending a variable from one class to another?

    Dear Java Users - please can you help me out here... I know that what I am asking should be straight forward BUT I just don't understand any of the responses people have put on the web....
    Here is what I am trying to do:
    This piece of code - creates a window with a simple textbox on it to enter a word...
    The button then calls another class file to open a new window...
    All I want to do is to take the word from the text box and print it in the new window....
    The first .java file I have is this:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class FrontPageGUI extends JFrame implements ActionListener
         //declare all instance variables for THIS per class
              JLabel lblInfoOne;
              JLabel lblButtonPopUp;
              JTextField txtName;
              JButton close;
              JButton popUp;
         public FrontPageGUI()
              //set characteristics of the JFrame object
              super("Title Bar");
              setSize(600,600);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              //we need to define a Container to place objects onto the frame - this is inside the JFrame Object Above
              Container ca = getContentPane( );
              ca.setSize(600,600);
              ca.setBackground(Color.white);
              ca.setLayout(null);                
              //define all other objects and set thier characteristics
              lblInfoOne     = new JLabel("Enter a word in the box above to send:");
              lblButtonPopUp = new JLabel("Click Here:");
              txtName          = new JTextField("");
              //create Button components
              close = new JButton("Close");
              popUp = new JButton("Click Me");
              //now add all objects to the container
              //Labels
              addXY(ca,lblInfoOne, 30, 160, 550,45);
              addXY(ca,lblButtonPopUp, 30, 210, 550,45);
              //TextField
              addXY(ca,txtName, 120, 100, 200,30);
              //Buttons
              addButtonXY(ca, popUp, 30, 260, 200, 45);
              addButtonXY(ca, close, 30, 310, 80, 30);
              // add the Container to the Frame     
              setContentPane(ca);          
         void addButtonXY(Container c, JButton cp, int x, int y, int w, int h)
               cp.setBounds(x,y,w,h);
               cp.addActionListener(this);
               c.add(cp);     
         void addXY(Container c, Component cp, int x, int y, int w, int h)
               cp.setBounds(x,y,w,h);
               c.add(cp);
         public void actionPerformed(ActionEvent event)
              if (event.getSource()== popUp)
                   //This is WHERE THE PROBLEM IS...
                   //Here I want to send to contents of the textfield - txtName
                   String temp = txtName.getText();
                   new PopUpGUI(temp);
              if (event.getSource()==close)
                   closeUp();
         void closeUp()
              System.exit(0);
              //dispose();
    //we need a driver program - this is the only time MAIN is used.
    public class FrontPage
         //create an instance of the GUI and showit
         public static void main(String args [])
              new FrontPageGUI();
                   The second .java file I have is this:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class PopUpGUI extends JFrame implements ActionListener
         //declare all instance variables ie per class
              JLabel headerLabel;
              JLabel sentLabel;          
              JButton close;
         public PopUpGUI(String Sent)
              //set characteristics of the JFrame object
              super("Pop Up Window");
              setSize(320,450);
              setVisible(true);
              //need to define a Container to place objects onto the frame
              Container ca = getContentPane( );
              ca.setSize(320,450);
              ca.setLayout(null);                
              //define all other objects and set characteristics
              headerLabel = new JLabel("New Window!"); //heading label
              sentLabel = new JLabel(Sent);
              close = new JButton("Close");
              //now add all objects to the container
              addXY(ca,headerLabel,10,10,380,80);
              addXY(ca,sentLabel,10,100,380,80);
              addButtonXY(ca, close, 50, 200, 100, 30); //Bottom Left
              // add the Container to the Frame     
              setContentPane(ca);
         //We need these 2 methods - EVERY TIME
         void addButtonXY(Container c, JButton cp, int x, int y, int w, int h)
               cp.setBounds(x,y,w,h);
               cp.addActionListener(this);
               c.add(cp);     
         void addXY(Container c, Component cp, int x, int y, int w, int h)
               cp.setBounds(x,y,w,h);
               c.add(cp);
         //What to do when the click happens
         public void actionPerformed(ActionEvent event)
              if (event.getSource()==close)
                   dispose();
                   //closeUp(); - Doesn't run CLOSEUP this time (i.e. exit program) - instead just DISPOSEs of the window
    //Driver class is in FrontPage.javaThis seems to work... but is it the best way to do it????
    Tony.

    Well,
    Using the constructor is the way to go. Otherwise create a method that takes the string as parameter.

  • Calling instance variable...

    Hi,
    Just wondeirng if I defined some instance variables in a class. If I want to call the variables in another class. Is it like <class_of_variables_are_defined>.<variables> ?

    Here are the codes I have written...I am still having a little trouble though
    Variables that I have defined in two different class...
    Ride.class
    public class Ride
         private String name;
         private int ticketsRequired, numberOfRiders;
         private float heightRequirement;
         public String getName()
              return name;
         public int getTicketsRequired()
              return ticketsRequired;
         public int getNumberOfRiders()
              return numberOfRiders;
         public float getHeightRequirement()
              return heightRequirement;
    TicketBooth.class
    public class TicketBooth
         private float moneyMade;
         private int availablePasses;
         public float TICKET_PRICE = 0.5f;
         public float PASS_PRICE = 16.5f;
         public float getMoneyMade()
              return moneyMade;
         public int getAvailablePasses()
              return availablePasses;
         public TicketBooth(int initAvailablePasses)
              availablePasses = initAvailablePasses;
                         .....Now when I try to use those private instance variables in Person.class, I got bunch of errors. I know private instances can only be used within the class they defined. How should I correct the code below?
    Person.class
                         public boolean buyPass(TicketBooth booth)
              if (hasPass == true && money >=  PASS_PRICE)
                   return true;
              else
                   return false;
         public boolean allowedToRide(Ride aRide)
              if (height >= heightRequirement &&
                 (hasPass == true || ticketCount >= ticketRequired))
                   return true;
              else
                   return false;
         public void getOn(Ride aRide)
              if ((allowedToRide(aRide) == true) && (hasPass == true))
                   availablePasses -= 1;
                   numberOfRiders += 1;
              else if(ticketCount >= ticketRequired)
                   numberOfRiders += 1;
                   ticketCount -= ticketsRequired;
                         .......

  • Redeclaration of instance variable in a subclass?

    public class Animal {
    String name;
    public Animal() {
    name="Generic Animal";
    public void makeSound() {
    System.out.println("Making an animal sound");
    public String getName() {
    return name;
    public class Dog extends Animal {
    String name;
    public Dog() {
    name = "Fido";
    public void makeSound() {
    System.out.println("BARK!");
    public String getName() {
    return name;
    public static void main(String[] args) {
    Animal a = new Dog();
    a.makeSound();
    System.out.println("a's name is " + a.name);
    Prints out "a's name is Generic Animal. But if I get rid of instance variable name in class Dog, it prints out "a's name is Fido". Why?

    Here is a corrected one and an inner class thrown in just for good measure:
    class Junk{
      int i;  //class variable has visibility throughout class.
      Junk(){
        i = 4; //assigning 4 to the class variable
      public void myMethod01(){
        int i = 25;
        System.out.println(i); //will print 25
        myInner mi = new myInner(); //inherits 4 to print
      public void myMethod02(){
        System.out.println(i); //will print 4 (if called before myMethod03--what does it print after?)
      public void myMethod03(int i){
        this.i = i;
        i = i - 3;
        System.out.println(i); // will print the argument value - 3
        System.out.println(this.i); //will print the value that was passed in and assigned to the class variable i;
      public static void main(String[] args){
        int i = 55;
        Junk m = new Junk();
        m.myMethod01();
        m.myMethod02();
        m.myMethod03(99);
        System.out.println(m.i); //will print 96 and then 99
        System.out.println(i); //will print 55
      class myInner{
        myInner(){
          System.out.println("myInner inherited value: " + i);  //prints inherited value of i
          myInner01(); // will print out 31
        public void myInner01(){
          int i = 31;
          System.out.println(i); //will print out 31
    }

  • Xcode debugger not showing my instance variables!!

    I hate asking questions like this.
    I set a breakpoint in an IBAction method 'pushed:' inside FooViewController.  At runtime I pressed a GUI button and processing stopped in pushed:.
    In the data-viewing pane of xcode, I see
    {code}
    self = (FooViewController *) 0x... etc.
    {code}
    Indented under this is
    {code}
    UIViewController = (UIViewController) { ...
    {code}
    Nowhere do I see any of my instance variables!!
    Now, they were synthesized from properties, but that doesn't matter, does it?
    The code that proceeds to set some instance variables runs fine.
    Why isn't xcode displaying self's instance vars?
    Thanks,
    Chap

    Yes, yours looks like I was expecting mine to look.
    Note that viewDidLoad (below) does work correctly, producing the expected results in the simulator!
    Hangman3ViewController.h:
    @interface Hangman3ViewController : UIViewController {
    @property (         nonatomic )           NSInteger  wordLength;
    @property ( retain, nonatomic )           NSString  *alphabet;
    @property (         nonatomic )           unichar    guess;
    @property (         nonatomic )           NSInteger  guessNo;
    @property ( retain, nonatomic )           NSMutableString *board;
    @property ( retain, nonatomic ) IBOutlet  UILabel   *boardLabel;
    @property ( retain, nonatomic ) IBOutlet  UILabel   *guessNumberLabel;
    @property ( retain, nonatomic ) IBOutlet  NSArray   *keyboardButtons;
    - (IBAction)letter:(id)sender;
    - (void)showBoard;
    @end
    and, Hangman3ViewController.m:
    #import "Hangman3ViewController.h"
    @implementation Hangman3ViewController
    @synthesize wordLength       = _wordLength;  // preprocessor command to gen getter/setter and instance variable
    @synthesize boardLabel       = _boardLabel;  // preprocessor command to gen getter/setter and instance variable
    @synthesize guessNumberLabel = _guessNumberLabel;  // Guess #n
    @synthesize keyboardButtons  = _keyboardButtons;   // array of buttons
    @synthesize alphabet         = _alphabet;    // A-Z unichars
    @synthesize guess            = _guess;       // unichar
    @synthesize guessNo          = _guessNo;     // int
    @synthesize board            = _board;
    - (IBAction)letter:(id)sender
                Get letter from sender - driven when key button is pressed.
                The button's tag is an int from 0-25, identifying what letter of the alphabet it is.
                Extract that unichar from ALPHABET as 'guess'.  Then, disable the button,
                which has been defined to have its text turn white (invisible) when disabled.
        UIButton *button = (UIButton *)sender;
        self.guess = [self.alphabet characterAtIndex: button.tag];
        NSLog(@"Received keystroke: %C", self.guess);
        [button setEnabled:NO];
    - (void)showBoard
        self.boardLabel.text = self.board;
        self.guessNumberLabel.text = [NSString stringWithFormat:@"Guess #%d", self.guessNo];
    - (void)dealloc
        [_boardLabel release];
        [_guessNumberLabel release];
        [_keyboardButtons release];
        [super dealloc];
    - (void)didReceiveMemoryWarning
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
        // Release any cached data, images, etc that aren't in use.
    #pragma mark - View lifecycle
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad
        NSLog(@"Hello from viewDidLoad");
        [super viewDidLoad];
        self.alphabet   = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // unichar string
        self.wordLength = 7;  // temp - will be set from flipside later on
        self.guessNo    = 1;
        [self.board setString:@"_______"]; // actually dynamic based on wordLength
        self.board = @"_______";
        [self showBoard];
    - (void)viewDidUnload
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    @end

  • Scope of instance variables clarification requested

    under the topic "Scope of instance variables" in the class notes for the course i'm doing it is stated:
    inside the class definition, the name can be prefixed by the keyword "this".
    e.g. available = this.balance + overdraft;
    in simple words, please explain what it means
    or:
    what is a class definition? and what does using "this" mean?
    i'll gladly take internet links on where i can find the answer to my own question if you don't have time.
    thanks a million!

    this can be regarded simply as a reference variable which points to the intance of the class it's used in.
    So this.fieldOne referer to the instance field fieldOne withing the current instance just as theOther.fieldOne refers to the instance field in another object.

  • Not able to access parent instance variable in outside of methods in child

    Hi,
    I am not getting why i am not able to access parent class instance variable outside the child class intance methods.
    class Parent
         int a;
    class Child extends Parent
         a = 1; // Here i am getting a compilation error that Syntax error on token "a", VariableDeclaratorId expected after this token
         void someMethod()
              a = 1;  // Here i am not getting any compilation error while accessing parent class variable
    }Can any one please let me know exact reason for this and what is the error talks about?
    Thanks,
    Uday
    Edited by: Udaya Shankara Gandhi on Jun 13, 2012 3:30 AM

    You can only put assignments or expressions inside methods, constructors or class initializors, or when declaring a variable.
    It has nothing to the with Child extending Parent.
    class Parent {
        int a = 1;
        { a = 1; }
        public Parent() {
            a = 1;
       public void method() {
           a = 1;
    }

  • Binding a JavaFX variable to a Java class instance variable

    Hi,
    I am pretty new to JavaFX but have been developing in Java for many years. I am trying to develop a JavaFX webservice client. What I am doing is creating a basic scene that displays the data values that I am polling with a Java class that extends Thread. The Java class is reading temperature and voltage from a remote server and storing the response in an instance variable. I would like to bind a JavaFx variable to the Java class instance variable so that I can display the values whenever they change.
    var conn: WebserviceConnection; // Java class that extends Thread
    var response: WebserviceResponse;
    try {
    conn = new WebserviceConnection("some_url");
    conn.start();
    Thread.sleep(10000);
    } catch (e:Exception) {
    e.printStackTrace();
    def bindTemp = bind conn.getResponse().getTemperature();
    def bindVolt = bind conn.getResponse().getVoltage();
    The WebserviceConnection class is opening a socket connection and reading some data in a separate thread. A regular socket connection is used because the server is not using HTTP.
    When I run the application, the bindTemp and bindVolt are not updated whenever new data values are received.
    Am I missing something with how bind works? Can I do what I want to do with 'bind'. I basically want to run a separate thread to retrieve data and want my UI to be updated when the data changes.
    Is there a better way to do this than the way I am trying to do it?
    Thanks for any help in advance.
    -Richard

    Hi,
    If you don't want to constantly poll for value change, you can use the observer design pattern, but you need to modify the classes that serve the values to javafx.
    Heres a simple example:
    The Thread which updates a value in every second:
    // TimeServer.java
    public class TimeServer extends Thread {
        private boolean interrupted = false;
        public ValueObject valueObject = new ValueObject();
        @Override
        public void run() {
            while (!interrupted) {
                try {
                    valueObject.setValue(Long.toString(System.currentTimeMillis()));
                    sleep(1000);
                } catch (InterruptedException ex) {
                    interrupted = true;
    }The ValueObject class which contains the values we want to bind in javafx:
    // ValueObject.java
    import java.util.Observable;
    public class ValueObject extends Observable {
        private String value;
        public String getValue() {
            return this.value;
        public void setValue(String value) {
            this.value = value;
            fireNotify();
        private void fireNotify() {
            setChanged();
            notifyObservers();
    }We also need an adapter class in JFX so we can use bind:
    // ValueObjectAdapter.fx
    import java.util.Observer;
    import java.util.Observable;
    public class ValueObjectAdapter extends Observer {
        public-read var value : String;
        public var valueObject : ValueObject
            on replace { valueObject.addObserver(this)}
        override function update(observable: Observable, arg: Object) {
             // We need to run every code in the JFX EDT
             // do not change if the update method can be called outside the Event Dispatch Thread!
             FX.deferAction(
                 function(): Void {
                    value = valueObject.getValue();
    }And finally the main JFX code which displays the canging value:
    // Main.fx
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import threadbindfx.TimeServer;
    var timeServer : TimeServer;
    var valueObjectAdapter : ValueObjectAdapter = new ValueObjectAdapter();
    timeServer = new TimeServer();
    valueObjectAdapter.valueObject = timeServer.valueObject;
    timeServer.start();
    Stage {
        title: "Time Application"
        width: 250
        height: 80
        scene: Scene {
            content: Text {
                font : Font {
                    size : 24
                x : 10, y : 30
                content: bind valueObjectAdapter.value;
    }This approach uses less cpu time than constant polling, and changes aren't dependent on the polling interval.
    However this cannot be applied to code which you cannot change obviously.
    I hope this helps.

  • Classes, and constructors and instance variables . . . oh my!

    wow, I am really struggling with the stuff we are doing in class for the last few days. I am going to post our assignment and point out specific things I don't understand. I don't understand some of the syntax and the overall logical flow of how parameters get passed back and forth, etc. I have been over our book and class examples and I am still confused.
    Here is one part of the assignment:
    "Create two instances of the MyDate class named begDate and endDate, by using the MyDate constructor after having prompted the user
    3 times for each date for values of a valid month, day, and year."
    Q: how do I create two instances using the constructor?
    (from our assignment) "Within the MyDate class:
         Include three private int variables, named month, day, and year.
         Include a constructor that sets (sets them to what?!) the values of month, day, and year."
    here is what I have:
    public class MyDate {
         private int month, day, year;
         public MyDate (int month, int day, int year){
              month = 0;
              day = 0;
              year = 0;
         }//MyDate Constructor(from our assignment) "Create two instances of the MyDate class named begDate and endDate, by using the MyDate constructor after having prompted the user 3 times for each date for values of a valid month, day, and year."
    and here is what I have in the executable class (it isn't much because I already have an error; it says I can't convert String to MyDate):
    public static void main(String[] args) {
              MyDate begDate = JOptionPane.showInputDialog("beg. month?");
         }I guess I don't know how to use the constructor correctly. Sorry, but I have tried to make this as clear as possible.

    I will give you a start:
    public static void main(String[] args) {
              MyDate begDate new MyDate(JOptionPane.showInputDialog("beg. month?"), JOptionPane.showInputDialog("beg. day?"), JOptionPane.showInputDialog("beg. year?"));
    public class MyDate {
         private int month, day, year;
         public MyDate (int month, int day, int year){
              this.month = month;
              this.day = day;
              this.year = year;
         }//MyDate Constructor
    /code]
    Haven't tested it, maybe made some type mismatches, but at leasy try this one                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Wrapper classes/ instance variables&methods

    can anyone provide me additional information on the wrapper classes.
    In addition, could someone please provide an explination of the- instance and class (variables+methods)

    Every primitive class has a wrapper class e.g.
    int - Integer
    float - Float
    long - Long
    char - Character
    etc. When a primitive is wrapped it becomes an object and immutable. Primitives are generally wrapped (either to make them immutable) or to be able to add them to the collections framework(sets, maps, lists which can only take objects, not primitives).
    An instance variable is a variable that each copy of the object you create contains, as is an instance method. Each instance you create (each copy of the object) contains its own copy of the variable and method.
    A class variable and method means that no matter how many objects you create, there will be one and only one copy of the variable and method.
    Hope this helps. Also see the java tutorial.

Maybe you are looking for

  • Read dimension member(master data) to ABAP internal table  in BPC 10.0 NW

    Hi all, I manage to read transaction data using this example [replacement for IF_UJ_MODEL~GET_APPL_DATA; I am now trying to read members(master data) from a dimension to a ABAP internal table but I have no idea how to. Can anyone advise me on how to

  • Issues Changing Images

    I really need some help! As part of a much, much larger project, a client has asked me to take an existing flash banner, change the graphic, text, and link to make 4 more that are almost identical. Though I haven't worked extensively with Flash, I am

  • Recording a DVD 8.5 Gig problems

    Hi guys yesterday i wanted to record all my music library which I have about 6.5 gigs of music and I was getting an error can someone tell me these error I have a lacie external DVD burner its a D2 DVD+_RW drive it records dual layer at 8 x max and n

  • Is QuickTime Pro what I need?

    Hi. I just received a Kodak zi8 video camera for Christmas that will record in HD but the extension is .mov . I would like to put my videos on DVD to give my family and I am finding out it is hard to burn .mov . Will purchasing QTPro let me be able t

  • How is iMac better than mac mini ??????

    Is there a iMac 2014  ?? how to identify ??? is it netter to buy iMac desk top as oppose to Mac Mini ????? what is a good dvd player to buy if I buy iMac desktop