write some lines of Java code that create a Screen object. Then call its clear method if (and only if) its number of pixels is greater than two million. (Don’t worry about things being logical here; the goal is only to write something that is syntactically correct—i.e., that would compile if we typed it in.)
Please find the required program below along with the comments and output:
class Screen { private int pixels; public Screen(int pixels) { //Constructor this.pixels = pixels; } public void clear(){ if(this.pixels > 2000000) { System.out.println("Screen Cleared!!"); } } public int getPixels() { //getter return pixels; } public void setPixels(int pixels) { //setter this.pixels = pixels; } } class Main { public static void main(String[] args) { Screen screen = new Screen(2100000); //Creating an object of Screen class screen.clear(); //calling clear method of screen object } }
----------------------------------
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.