Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to use super to activate constructor chaining in class inheritance with Java

1 Answer

0 votes
class Person  {  
    String name, profession;   
    int id;  
        
    public Person(int id, String name, String profession) {  
        this.id = id;  
        this.name = name;  
        this.profession = profession;  
    }  
}  
class Company extends Person {  
    int department;  
    
    public Company(int id, String name, String profession, int department) {  
        super(id, name, profession);  
        this.department = department;  
    }  
}
public class Test {  
    public static void main (String args[]) {  
        Company c = new Company(983872, "Dan", "Programmer", 3);  
        System.out.println("id = " + c.id + " name = " + c.name + 
                           " profession = " + c.profession + " department = " + c.department);  
    }  
}  



/*
run:

id = 983872 name = Dan profession = Programmer department = 3

*/

 



answered Sep 27, 2019 by avibootz

Related questions

1 answer 153 views
1 answer 150 views
1 answer 196 views
...