Dont accept String name
import java.util.Scanner; class A { int hno; String city,state; void getdata() { Scanner sc = new Scanner(System.in); System.out.println("\n\t enter the house number"); hno = sc.nextInt(); System.out.println("\n\t enter the city name"); city = sc.nextLine(); System.out.println("\n\t enter the state name"); state = sc.nextLine(); } void display() { System.out.println("House no : "+hno +""+"\n"+ "City name : "+city +""+"\n"+ "state name: "+state); } } public class SimpleI extends A { public static void main(String[] args) { SimpleI hcs = new SimpleI(); hcs.getdata(); hcs.display(); } }