Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,904 questions

11,012 answers

573 users

How to use this in class with Java

2 Answers

0 votes
package javaapplication1;

class Worker {
  String name;
  int age;
  Worker(String name, int age) {
    this.name = name;
    this.age = age;
  }
  void print(){
    System.out.println("Name: " + name + " Age: " + age);
  }
}

public class JavaApplication1 {

    public static void main(String[] args) {
        Worker w = new Worker("Dom", 50);
        w.print();
    }
}


/*
run:

Name: Dom Age: 50

*/

 




answered Jul 5, 2017 by avibootz
0 votes
package javaapplication1;

class Worker {
  String name;
  int age;
  Worker(String name){
    this.name = name;
  }
  Worker(String _name, int _age) {
    this(_name);
    age = _age;
  }
  void print(){
    System.out.println("Name: " + name + " Age: " + age);
  }
}

public class JavaApplication1 {

    public static void main(String[] args) {
        Worker w = new Worker("Rebecca", 40);
        w.print();
    }
}


/*
run:

Name: Rebecca Age: 40

*/

 




answered Jul 5, 2017 by avibootz
...