aspose file tools
The moose likes Beginning Java and the fly likes initialisation confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "initialisation confusion" Watch "initialisation confusion" New topic
Author

initialisation confusion

Rajat Sarkar
Greenhorn

Joined: Sep 07, 2008
Posts: 18
class Dog
{
private int teeth_number;
private boolean isMad;
private String name;
private int size;

public Dog(String s,boolean ad,int si)
{
name=s;
isMad=ad;
size=si;
}

public String showName()
{
return name;
}

public int showteeth()
{
return teeth_number;
}
}

public class TestDog
{
public static void main(String[] args)
{
Dog mydog=new Dog("Rocky",false,50);
System.out.println("name : "+mydog.showName()+" teeth number : "+mydog.showteeth());
}
}

In the Dog's constructor we don't initialise teeth_number.Then how we get the value 0 for it when we create Dog object?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32633
    
    4
All fields have a default value: in the case of numbers 0. This doesn't apply to local variables.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: initialisation confusion
 
Similar Threads
How does Set identify duplicates(by == or equals)
Which is best to use in hashcode?
Comparing Maps hashcodes problem??
K&B chapter 7 question 15. Collections.
Equals and HasCode