Không xuất được lương đã tính

import java.io.*;
import java.util.*;
abstract class NhanVien{
	protected String ten;
	protected int luong;
	public NhanVien(){
	} 
	public NhanVien(String ten,int luong){
		this.ten = ten;
		this.luong = luong;
	}
	public void nhap(){
		Scanner sc = new Scanner(System.in);
		System.out.println ("Ten: ");
		ten = sc.nextLine();
		System.out.println ("Luong: ");
		luong = sc.nextInt();
	}
	public void xuat(){
		System.out.println (ten+"\t"+luong);
	}
	abstract int tinhLuong();
}
class QuanLy extends NhanVien{
	public QuanLy(){
		super();
	}
	public QuanLy(String ten,int luong){
		super(ten,luong);
	}
	public int tinhLuong(){
		int luongQL = 4*luong;
		return luongQL;
	}
}
class PhucVu extends NhanVien{
	public PhucVu(){
		super();
	}
	public PhucVu(String ten,int luong){
		super(ten,luong);
	}
	public int tinhLuong(){
		int luongPV = 2*luong;
		return luongPV;
	}
}
class Demo
{
	public static void main (String[] args) {
		NhanVien pv = new PhucVu();
		pv.nhap();
		pv.xuat();
		pv.tinhLuong();
    }
}

Show errors đi :smile: hên xui mò dùm cho
À, ở method tinhLuong()

public int tinhLuong(){
		int luongPV = 2*luong;
		return luongPV;
	}

Thì nó return. Thì lúc invoke
pv.tinhLuong(); nó đâu có nhận nhiệp vụ in ra đâu
thử
System.out.println (pv.tinhLuong()); xem thay đổi được gì không?

2 Likes

yeah ok r bác. tks bác nha

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?