---
title: "Can we declare the main method of our class as private?"  
description: "Can we declare the main method of our class as private?"  
author: "Bhavya Varma"  
published: 2017-12-20  
canonical: https://answers.mindstick.com/qa/31863/can-we-declare-the-main-method-of-our-class-as-private  
category: "technology"  
tags: ["java programming"]  
reading_time: 1 minute  

---

# Can we declare the main method of our class as private?

Can we [declare the main method](https://www.mindstick.com/interview/2388/can-you-declare-the-main-method-as-final-in-java) of our class as private?

## Answers

### Answer by Hemant Patel

Yes, we can! ***it will compile, but it will not run***. In Java we declare the main [method](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) of our class as private, *it compiles without errors, but it can not be taken as the entry point of your application*. When you compile your application it will compile without any error, but at runtime, it throws an exception **the main method is not public**. On the basis of the above discussion, we reached the conclusion that's you can declare the main method as private but at runtime, it says the main method is not public.

## *I hope it's informative for you...*


---

Original Source: https://answers.mindstick.com/qa/31863/can-we-declare-the-main-method-of-our-class-as-private

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
