Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:12:02+00:00 2026-06-16T09:12:02+00:00

//Vehicle.java import java.util.Random; class VehicleConstructor{ private int speed; private int timeDriven; private int run;

  • 0
//Vehicle.java

import java.util.Random;

class VehicleConstructor{

    private int speed;
    private int timeDriven;
    private int run;
    private int startSpeed; //Pradinis greitis

    public VehicleConstructor() {
        setSpeed();
        System.out.println("Vehicle");
    }

    private void setSpeed(){
        int minSpeed = 1;
        int maxSpeed = 40;

        Random random = new Random();
        this.startSpeed = random.nextInt(maxSpeed - minSpeed + 1) + minSpeed;
    }

    protected int getSpeed(){
        return startSpeed;
    }
}

class Bicycle extends VehicleConstructor{

    public void Bicycle(){
        System.out.println(getSpeed());
    }
}

public class Vehicle{
    public static void main(String[] args){
        Bicycle bicycle = new Bicycle();
    }
}

I want to create object Bicycle which extends VehicleConstructor and call method getSpeed() from parent. The problem is that i get an error:

Error: Main method not found in class Bicycle, please define the main
method as: public static void main(String[] args)

As far as i know in Java constructors are with the same name as the class, so i have

 public void Bicycle(){
        System.out.println(getSpeed());
    }

But error says that i need public static void main, and so the other classes also need to be with static, but i don’t want this. Is it possible somehow create object without need of static method in it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:12:03+00:00Added an answer on June 16, 2026 at 9:12 am
    public void Bicycle(){ //This is a method
    
    public  Bicycle(){ //This is a constructor
    

    Constructor’s don’t have any return type, not even void.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.util.Random; class VehicleConstructor{ private int startSpeed; public VehicleConstructor() { setSpeed(); System.out.println(VehicleConstructor); } private
class Vehicle { public int wheels; public int lights; } class Car extends Vehicle
Consider this simple program. The program has two files: File Vehicle.java class Vehicle {
My Vehicle type: public class Vehicle : EntityObject { private Lazy<string> _nameFromDelegate = null;
Given a Vehicle class and a VehicleProperty class... public class Vehicle { public virtual
Assume a class Vehicle has a method called StartEngine, and in my subclass called
I have an Vehicle class. From Vehicle, I extend Car class (and some others
Suppose I have a class hierarchy as follow: class Vehicle; class Car extends Vehicle;
Okay, so, for example, let's say I have an abstract class called Vehicle. The
I am looking for a method to insert random XML data in Java (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.