---
title: "non-static method  in java"  
description: "non-static method  in java"  
author: "Lady Bird Johnson"  
published: 2013-07-09  
updated: 2013-07-09  
canonical: https://www.mindstick.com/forum/1269/non-static-method-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# non-static method  in java

Hi [developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs)!\
i have [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) in following code.can you rectify it please\
Thanks in advance.This is my [source code](https://www.mindstick.com/forum/33476/pls-send-me-source-code-for-changing-passward-in-asp-dot-net-i-tried-so-much-from-google-but-its-not-workining):JCatalog:\

```
package newpackage;import java.awt.Component;public class JCatalog extends javax.swing.JPanel {    public JCatalog() {        initComponents();    }    public Component getComponent() {        return this;    }JPanelTicket:package javaapplication5;import javax.swing.JPanel;import newpackage.JCatalog;public abstract class JPanelTicket extends JPanel {    JCatalog jcat;    public JPanelTicket() {        initComponents();    }    public void init(){        jcat = (JCatalog) JCatalog.getComponent(); //Here's the problem    }
```

## Replies

### Reply by shreesh chandra shukla

Hi\
solution:at the core of static methods, you know the only class name is able to call the static method of it's own.so!You cannot call a non-static method using class, like JCatalog.getComponent()A non-static method can only be called with instance jcat.getComponent()I see that you have an reference maintained of type JCatalog named jcat. Make sure you initialize it somewhere OR set the instance using setter method. And use this instance to call the getComponent() method\

```
public abstract class JPanelTicket extends JPanel {    JCatalog jcat;    public JPanelTicket() {        jcat = new JCatalog();        initComponents();    }    public void init(){        jcat = jcat.getComponent(); //Here's the problem    }}
```

....................................................................................................alternatively.............................................................................................

```
public abstract class JPanelTicket extends JPanel {    JCatalog jcat;    public JPanelTicket() {        initComponents();    }    public void init(){        jcat = jcat.getComponent(); //Here's the problem    }    public void setJCatalog(JCatalog jcat) {        this.jcat = jcat;    }}
```

i hope this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) will be helpful for you.\
\


---

Original Source: https://www.mindstick.com/forum/1269/non-static-method-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
