+ 2

What is wrong in my code below?

//be attentive to access modifiers class Standard { protected void draw() { System.out.println("Drawing"); } private void write() { System.out.println("Writing"); } } //fix the class class Pro extends Standard{ protected void useEffects() { System.out.println("Using Effects"); } protected void changeResolution() { System.out.println("Changing Resolution"); } } public class Main { public static void main(String[] args) { Standard standard1 = new Standard(); Pro pro1 = new Pro(); //standard version standard1.draw(); standard1.write(); //Pro version pro1.draw(); pro1.write(); pro1.useEffects(); pro1.changeResolution(); } } Please help me

13th Oct 2022, 3:43 PM
Kanagaraj Arunthadhy
Kanagaraj Arunthadhy - avatar
8 Answers
+ 4
I fixed it on my own. Just need to change public to protected. Here is my code 👇 class Standard { protected void draw() { System.out.println("Drawing"); } // this should be changed protected void write() { System.out.println("Writing"); } } class Pro extends Standard{ protected void useEffects() { System.out.println("Using Effects"); } protected void changeResolution() { System.out.println("Changing Resolution"); } } public class Main { public static void main(String[] args) { Standard standard1 = new Standard(); Pro pro1 = new Pro(); standard1.draw(); standard1.write(); pro1.draw(); pro1.write(); pro1.useEffects(); pro1.changeResolution(); } }
13th Oct 2022, 4:04 PM
Kanagaraj Arunthadhy
Kanagaraj Arunthadhy - avatar
+ 3
That write() method in Standard class is private access so you can't access this from outside that class. pro1.write() ; raise error.... standard.write(); also wrong..
13th Oct 2022, 3:47 PM
Jayakrishna 🇼🇳
+ 2
So how to fix it?
13th Oct 2022, 3:50 PM
Kanagaraj Arunthadhy
Kanagaraj Arunthadhy - avatar
+ 2
Thanks for your help "https://www.sololearn.com/Profile/12469228/" Jayakrishnain Sir
13th Oct 2022, 4:05 PM
Kanagaraj Arunthadhy
Kanagaraj Arunthadhy - avatar
+ 2
Rahmat
26th Oct 2023, 6:00 PM
Otabek
+ 1
What is your task by this code?
13th Oct 2022, 3:55 PM
Jayakrishna 🇼🇳
+ 1
class Standard { public void draw() { System.out.println("Drawing"); } public void write() { System.out.println("Writing"); } } //fix the class class Pro extends Standard { protected void useEffects() { System.out.println("Using Effects"); } protected void changeResolution() { System.out.println("Changing Resolution"); } } public class Main { public static void main(String[] args) { Standard standard1 = new Standard(); Pro pro1 = new Pro(); //standard version standard1.draw(); standard1.write(); //Pro version pro1.draw(); pro1.write(); pro1.useEffects(); pro1.changeResolution(); } }
21st Oct 2023, 4:14 PM
Mbengue Mbor
Mbengue Mbor - avatar
+ 1
Make your private life public
21st Oct 2023, 4:15 PM
Mbengue Mbor
Mbengue Mbor - avatar