Answer to Question #246957 in C++ for Yashu

Question #246957
Implement a single inheritance program where base class is Clock & derived class is Alarm_Clock . Base class should have at least one member with private access, one member with protected access, one with public access. Clearly differentiate between different access specifiers. While designing classes make sure you add valid data members & member functions. Also try to analyze the difference between private, public & protected mode of inheritance.
1
Expert's answer
2021-10-05T23:13:48-0400


public class Main
{
	public static void main(String[] args) {
		Alarm_Clock a=new Alarm_Clock("07:13.23");
		System.out.println("Current time: "+a.getCurrentTime());
	}
}


class Clock{
    private String current_time;
    protected String getCurrentTime(){
        return current_time;
    }
    public Clock(String c ){
        current_time=c;
    }
}


class Alarm_Clock extends Clock{
    public Alarm_Clock(String c){
        super(c);
    }
}

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS