











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












class Box{
private int L,W,H;
public void test(Box b){
b.H=10;
}
}
public class Flower { private int petalCount = 0; private String s = new String("null"); Flower(int petals) { petalCount = petals; System.out.println( "Constructor w/ int arg only, petalCount= "
Flower() { this("hi", 47); System.out.println( "default constructor (no args)"); } void print() { //! this(11); // Not inside non-constructor! System.out.println( "petalCount = " + petalCount + " s = "+ s); } public static void main(String[] args) { Flower x = new Flower(); x.print(); } } ///:~ (source : Internet)
public class Box{ int x,y,w; { x=y=x=5; } }
Initialization block for static fields
public class Box{ int x,y,z;
static int boxCount;
static { boxCount=0; x=y=z=5;
} }
class Employee 26.{
// three overloaded constructors
public Employee(String n, double s)
{
name = n;
salary = s;
}
public Employee(double s)
{
// calls the Employee(String, double) constructor
this("Employee #" + nextId, s);
}
// the default constructor
public Employee()
{
// name initialized to ""--see below
// salary not explicitly set--initialized to 0
// id initialized in initialization block
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
Core Java™ 2: Volume I–Fundamentals 176
Example (Java standard library class) public class Window extends Container{ String warningString; }