0

why declare at class computer able to run no error but error when put below class laptop?

public class Computer { Computer (){ System.out.println("Constructor of Computer Class."); } void computer_method() { System.out.println("Power gone! Shut down your PC Soon......"); }    public static void main(String[] args) {    Computer my=new Computer(); Laptop your=new Laptop();    my.computer_method(); your.laptop_method(); }          } class Laptop { Laptop(){ System.out.println("Constructor of laptop class"); } void laptop_method(){ System.out.println("9% Battery available."); }

5th Nov 2020, 8:31 AM
mahsa
mahsa - avatar
4 Answers
+ 5
Your code is incomplete class computer is missing, First create a Class named Computer and put all this code inside that class.
5th Nov 2020, 8:48 AM
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ - avatar
+ 2
JavaScript is a different language
5th Nov 2020, 9:06 AM
Abhay
Abhay - avatar
0
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ why declare at class computer able to run no error but error when put below class laptop?
5th Nov 2020, 9:14 AM
mahsa
mahsa - avatar
0
Coding CAT thank you. i get that. but what i meant was, why the program cannot run when the "public static void main" was declare in the Laptop class? But it can run perfectly when it is declared under the Computer class.
5th Nov 2020, 12:22 PM
mahsa
mahsa - avatar