Answer the question
In order to leave comments, you need to log in
How to extend a java class with java.io?
There is a GetSet class that needs to be extended with a built-in class from the java.io* package
package com.firstproject.getset;
public class GetSet {
private int intVariable;
private double doubleVariable;
private String stringVariable;
public int getIntVariable(){
return intVariable;
}
public void setIntVariable(int newIntVariable){
intVariable = newIntVariable;
}
public double getDoubleVariable(){
return doubleVariable;
}
public void setDoubleVariable(double newDoubleVariable){
doubleVariable = newDoubleVariable;
}
public String getStringVariable(){
return stringVariable;
}
public void setStringVariable(String newStringVariable){
stringVariable = newStringVariable;
}
public void message(){
System.out.println("Int variable = "+intVariable+
"\nDouble variable = "+doubleVariable+
"\nString variable = "+"\""+stringVariable+"\"");
}
}
import java.io.*;
import com.firstproject.getset.*;
public class Main{
public static void main(String[] args){
GetSet getset = new GetSet(Reader);
getset.setIntVariable(1);
getset.setDoubleVariable(6.66);
getset.setStringVariable("Hello, World!");
getset.message();
}
}
import java.io.*;
import com.firstproject.getset.*;
public class Main{
public static void main(String[] args){
GetSet getset = new GetSet(InputStreamReader(System.in));
getset.setIntVariable = getset.readLine();
getset.setDoubleVariable = getset.readLine();
getset.setStringVariable = getset.readLine();
getset.message();
}
}
Answer the question
In order to leave comments, you need to log in
So, and do as you yourself said - expand.
In this case, "inherit":
import java.io.BufferedReader;
import java.io.Reader;
public class GetSet extends BufferedReader {
private int intVariable;
private double doubleVariable;
private String stringVariable;
public GetSet(Reader in, int sz) {
super(in, sz);
}
public GetSet(Reader in) {
super(in);
}
public int getIntVariable() {
return intVariable;
}
public void setIntVariable(int newIntVariable) {
intVariable = newIntVariable;
}
public double getDoubleVariable() {
return doubleVariable;
}
public void setDoubleVariable(double newDoubleVariable) {
doubleVariable = newDoubleVariable;
}
public String getStringVariable() {
return stringVariable;
}
public void setStringVariable(String newStringVariable) {
stringVariable = newStringVariable;
}
public void message() {
System.out.println("Int variable = " + intVariable +
"\nDouble variable = " + doubleVariable +
"\nString variable = " + "\"" + stringVariable + "\"");
}
}
public void setIntVariable(String s) {
intVariable = Integer.parseInt(s);
}
I'm a total noob at JAAA, just trying to improvise and improve my learning process with google
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question