java - Superclass Point - Subclass Line? Can anyone tell me how to make the subclass line use the x and y declared in class Point? -


import java.util.scanner;  public class point {      scanner in = new scanner(system.in);     int x;     int y;  public void ans() {         system.out.println("enter value x: ");        x = in.nextint();          system.out.println("enter value y: ");         y = in.nextint();          system.out.println("your point is: "+ "(" +x+ "," +y+ ")");     } } 

line class!

import java.util.scanner;  public class line extends point {      scanner scan = new scanner(system.in);      point point = new point();      int x = point.x;      int y= point.y;      int x1;     int y1;      int[] a= {x1,y1};     int[] b= {x,y};      public void add(){           system.out.println("enter value x1; ");         x1 = scan.nextint();           system.out.println("enter value y1; ");         y1 = scan.nextint();          system.out.println("");         ans();          system.out.println("your line is: "+ "(" +x+ "," +y+ ")" +"(" +x1+ "," +y1+ ")");     }      } 

in output asks declaring x , y values again!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -