Home  >  Forum  >  Core Java
Post New Query

Type mismatch: cannot convert from void to String



Asked on March 12, 2015
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from void to String

class Clock {
String time;
void setTime(String t){
time = t;
}
void getTime(){
return time;
}

}

class ClockTest{
public static void main(String[] args) {
Clock c = new Clock();
c.setTime("10:34");
String tod = c.getTime();
System.out.println("time: " + tod);
}
}



Replied on March 12, 2015
Mismatch type is in your getter and setter. You return a string value and declared it as void.

 class Clock {
String time;
void setTime(String t){
time = t;
}
String getTime(){
return time;
}

}


Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us