This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes creation of object for  a class in static method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creation of object for  a class in static method" Watch "creation of object for  a class in static method" New topic
Author

creation of object for a class in static method

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
class Ex2 {
public static void main(int args) {
class Hii{
}
}
public static void main(String[] args) {
}
}
How can we create an object for a class in static method and the method has parameters to pass? any help please


Thanks,
Shekar
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,
Is your question "How can I create an instance of "Hii" from code in main(String[]) ? The answer is, simply enough, that you can't. Classes local to a method can't be constructed in any code outside that method; whether there are parameters, or whether the methods are static, have no bearing on the question.


[Jess in Action][AskingGoodQuestions]
 
wood burning stoves
 
subject: creation of object for a class in static method
 
Similar Threads
JAVAC not found ??? I cant compile - help
why this outout
can't run
Some doubt about Method calling
Java noob needs help