63 064
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #47370 in Java | JSP | JSF for neha reddy

Question #47370
Create a class Count with a data member current_count with proper access specifier. Create another tester class (which has main method) to instantiate two counters of Count class.
In the Count class create 2 constructors: default and parameterized constructors.
In Count class create accessors for the current_count data member
Expert's answer
Code(Count.java).  
public class Count {
       private int count_member;
      
       /**
        * Default constructor.
        */
       public Count() {
             count_member = 0;
       }
      
       /**
        * Parameterizedconstructor.
        * @param count_member
        */
       public Count(int count_member) {
             this.count_member = count_member;
       }
      
       /**
        * count_memnber accessor.
        */
       public int get_count_member() {
             return count_member;
       }
 
       /**
        * count_member muttator.
        */
       public void set_count_member(int count_member) {
             this.count_member = count_member;
       }
      
}
Code (Main.java).
public class Main {
       public static void main(String[] args) {
             Count ct1 = new Count();
             Count ct2 = new Count(1);
             System.out.format("ct1.count_member: %d\n", ct1.get_count_member());
             System.out.format("ct2.count_member: %d", ct2.get_count_member());
       }
}
Input/Output.
ct1.count_member: 0
ct2.count_member: 1

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions