Home  >  Forum  >  Core Java
Post New Query

Type mismatch: cannot convert from void to String


joined on
September 16,2014
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);
}
}
joined on
March 15,2013
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








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us