Hi Michel,

You can declare (provide a type and identifier) and initialize a variable
all in a single line. However, you cannot use a variable without first
declaring it. Also, you have to initialze a variable before using it in your
program.

char option; is the declaration
option = 'C'; is the initialization

and char option='C' does both the declaration and initialization in one
line. Either way is acceptable.

Hope this helps,

Andre

On Wed, Dec 22, 2010 at 6:23 PM, Michel <michelana...@gmail.com> wrote:

> Questions 1
> What is the difference between the following 2 declaration statements?
>
> char option;
> option = 'C';
>
> and
>
> char option='C';
>
>
> Questions 2
> Why sometimes we initialize variables and sometimes we don’t?
> For example in the following program, we initialized the string name,
> but we did not initialize the string msg:
>
> 1 import javax.swing.JOptionPane;
> 2
> 3 public class GetInputFromKeyboard {
> 4
> 5 public static void main( String[] args ){
> 6 String name = "";
> 7 name=JOptionPane.showInputDialog(“Please enter your name");
> 8 String msg = "Hello " + name + "!";
> 9 JOptionPane.showMessageDialog(null, msg);
> 10 }
>
> --
> To post to this group, send email to
> javaprogrammingwithpassion@googlegroups.com
> To unsubscribe from this group, send email to
> javaprogrammingwithpassion+unsubscr...@googlegroups.com<javaprogrammingwithpassion%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en

-- 
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to 
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to