Click here to Skip to main content
15,917,481 members

Comments by skwoals (Top 3 by date)

skwoals 23-Sep-21 12:27pm View    
I see. Thank you!
skwoals 23-Sep-21 6:11am View    
Nope they didn't teach inheritance when I was in 1st year. Our topic now is Object-Oriented Programming and he discussed that example^ of program using inheritance. I'm so confused because he didn't teach us how to use it with scanner so I have no idea how to put scanner and inheritance in the same program and how to make it work.
skwoals 23-Sep-21 3:14am View    
Thank you. So I don't need to use inheritance for the program? Why did my prof send us this code for reference? I don't know how to do it with scanner..

class sample {

int z;
/////////////////////////////////////
public void addition(int x, int y) {
z = x + y;
System.out.println("The sum of the given numbers:"+z);
}
//////////////////////////////////////
public void Subtraction(int x, int y) {
z = x - y;
System.out.println("The difference between the given numbers:"+z);
}
//////////////////////////////////////
public void multiplication(int x, int y) {
z = x * y;
System.out.println("The product of the given numbers:"+z);
}
}

public class example extends sample {
public static void main(String []args) {
int a = 20, b = 10;
example demo = new example();
demo.addition(a, b);
demo.Subtraction(a, b);
demo.multiplication(a, b);
}
}