User defined package problem

User defined package problem

View Answers

September 1, 2009 at 6:27 PM

How do you access non static method of a class ?
i.e. obj.method() right !

So, if u have a class which is not having the given method how will u access it ?
Just study the following code carefully

class A
{
int a;
void show()
{
System.out.print("a is "+a);
}
}
class B
{
public static void main(String args[])
{
B bobj=new B();
bobj.a=100;//1
bobj.show();//2
}
}

Lets forget about class A for timbing.
Look at class B...............
It does not have a member so called 'a' and not even show().
Hence compiler will definately give an error.

above prg compiles if We write class B as
class B extends A

Coming to ur prg.
The error is you can access Public_Demo1 member method only if have instantiated (created an object) of it in Public_Demo2.
So, try it out, as
package mypack1;
class Public_Demo2
{
public static void main(String ar[])
{
Public_Demo1 pd=new Public_Demo1();
pd.show();
}
}
}

your prg will compile. you must be wondering why eg with no package statement is being provided to u. Its because classes/interfaces with no package statement is put into a default package thats without a name.
so eg provided will work similarly to which u have tried. if u still wish to add a package statement u can go ahead. Happy programming..............









Related Tutorials/Questions & Answers:
User defined package problem - Java Beginners
User defined package problem  Hello friend, i was trying to execute the user-defined packages according to the chart that has been given..., it has been given that default members can be accessed "within the same package non
user defined date class
user defined date class  Develop a user defined date class with public.Fill the members using existing class method.implement the methods for finding current date(),days between method,advanced days and after days
Advertisements
user defined date class
user defined date class  Develop a user defined date class with public.Fill the members using existing class method.implement the methods for finding current date(),days between method,advanced days and after days
verfication of user login and then redirecting it to user defined page
verfication of user login and then redirecting it to user defined page ...() to redirect to a user defined page..but..wen i press the submit button,the html page calls teh servlet..but..the servlet.is not redirecting to a user defined
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other
user defined function inside a jsp
user defined function inside a jsp  how to write a user defined function inside a jsp page
User Defined Exception In Java
User Defined Exception In Java In terms of programming when we talk about.... Then you will be required to create your own exception. A user defined exception can... for defining a user defined exception your exception class should be the subclass
USER DEFINED CLASS
USER DEFINED CLASS  hi please help me with my project: Exercise # 1 Create a java program for a class named MyDate that contains data members and a constructor that meet the criteria in the following list. This class is used
write a program to create a user defined
write a program to create a user defined   plz send me code   Hi Friend, Please specify what do you want to create?ADS_TO_REPLACE_1 Thanks
Java User-defined Exception
Java User-defined Exception In this tutorial, you will learn about the User-defined Exceptions. These custom exceptions actually all the programmer... a user defined exception if the student marks entered, is less than fifteen
user defined styles for datetimepicker in struts2
user defined styles for datetimepicker in struts2  Hi, sample code: <%@taglib prefix="sx" uri="/struts-dojo-tags"%> Issue: I need to have my own styles for the displyed date picker. is it possible? Can anyone help
user defined styles for datetimepicker in struts2
user defined styles for datetimepicker in struts2  Hi, I am using dojo plugin for displaying datetimepicker. i want to change the colour of the date picker which is in "blue" by default . Please any one can help me
ModuleNotFoundError: No module named 'django-user-defined-fields'
ModuleNotFoundError: No module named 'django-user-defined-fields'  Hi...: No module named 'django-user-defined-fields' How to remove the ModuleNotFoundError: No module named 'django-user-defined-fields' error? Thanks
ModuleNotFoundError: No module named 'mkdocs-user-defined-values'
ModuleNotFoundError: No module named 'mkdocs-user-defined-values'  Hi...: No module named 'mkdocs-user-defined-values' How to remove the ModuleNotFoundError: No module named 'mkdocs-user-defined-values' error? Thanks
ModuleNotFoundError: No module named 'pyjxslt-user-defined-address'
ModuleNotFoundError: No module named 'pyjxslt-user-defined-address'  ...: No module named 'pyjxslt-user-defined-address' How to remove the ModuleNotFoundError: No module named 'pyjxslt-user-defined-address' error
ModuleNotFoundError: No module named 'django-user-defined-fields'
ModuleNotFoundError: No module named 'django-user-defined-fields'  Hi...: No module named 'django-user-defined-fields' How to remove the ModuleNotFoundError: No module named 'django-user-defined-fields' error? Thanks
PHP User Defined Function
PHP User Defined Function An user-defined function saves  us from  rewriting the same code again and again and helps us to make our application... functions as per the need. General structure of the user defined function is:ADS
JavaScript User Defined Functions
JavaScript User-Defined Functions: An user-defined function saves  us from  rewriting the same code again and again and helps us to make our... can make your own as per the need. General structure of the user defined
Remove attribute in user defined session - JSP-Servlet
Remove attribute in user defined session  Hi, How we can set remove attribute for user defined session. I am appreciating if you are sending solution as soon as possible? Thanks, Sanat Kumar
Making Custom (User Defined) Exceptions
Making Custom (User Defined) Exceptions   ... Making Custom (User Define Exceptions) So far you would have been known, how... appropriate and that mechanism of handling exception is called Custom or User
to make a google map point to user defined location
to make a google map point to user defined location  Hi, i wish to develop an google map,that takes the input from a form(city,area &Country... the desired location of the user
user defined subclass of throwable class - Java Beginners
user defined subclass of throwable class  Dear Sir,pls help me to write this pgm: Program to illustrate the use of user defined subclass of throwable class  Hi Friend, Try the following: 1) public class
jsp- adding user defined functions to a jsp
jsp- adding user defined functions to a jsp  Trying to write the function as below but getting errors. Can you please identify the cause of error and how to correct it. <% public String retrieveAndClearErrorMessage
URGENT: User Defined Classes - Java Beginners
URGENT: User Defined Classes  Can someone help me? Design and implement the class Day that implements the day of the week in a program. The class... the definitions of the methods to implement the operations for the class Day, as defined
ModuleNotFoundError: No module named 'package-user'
ModuleNotFoundError: No module named 'package-user'  Hi, My Python... 'package-user' How to remove the ModuleNotFoundError: No module named 'package-user' error? Thanks   Hi, In your python
Using a user defined non-packaged servlet class in jsp. - JSP-Servlet
Using a user defined non-packaged servlet class in jsp.  i want know that how to use a user defined java servlet function's, variables and methods of a user defined java servlet in jsp.if possible plz try to explain with a simple
import user-define package - Applet
import user-define package  how to import user-define package to the frame/graphic of the applet. could i create a new frame or not ?? please help me ...  Hi friend, import java.io.*; import java.awt.*; import
How to create file and save it into user defined path using jsp/servlet?
How to create file and save it into user defined path using jsp/servlet?  Hi.. Onclick event I have created one file.When file will create it should asked where to save file(like browse option
problem of static in jsp page by multiple user access
problem of static in jsp page by multiple user access  hi , i am continuing my online exam project,but i have a Singleton class which i am invoking from my jsp page , ths page can access by more number of users .every user
user-define package for applet - Java Beginners
user-define package for applet  how to import a user-define package to applet ??  Hi import javax.swing.*; import java.awt.Graphics; import javax.swing.JApplet; public class WelcomeLines extends JApplet
how to import user-define package to applet - Applet
how to import user-define package to applet  how to import user-define package to applet... can u write a java coding can execute in jdk only .... thx...  Hi friend, import java.applet.*; import java.util.
package:
package:  i hv created created a package and save it into D... but it can't run with following command: java mypackage.classname what's problem... in a package world. The we specify the keyword package with the name
package:
package:  i hv created created a package and save it into D... but it can't run with following command: java mypackage.classname what's problem... in a package world. The we specify the keyword package with the name
package
package  write a package for games which have two classes indoor... specifier and also use the finalize() method   We have created a package named games where we have defined two classes Indoor and Outdoor. In the main
Package
Package  Create a Package named com.example.code. Write few classes, interface and abstract classes. Now create a class names PackageDemo that uses the classes of this package from other package
Package
Package  Create a Package named com.example.code. Write few classes, interface and abstract classes. Now create a class names PackageDemo that uses the classes of this package from other package
ptor is not defined
ptor is not defined  Hi, I am trying to use the protractor for HTML test cases. Due to some reason it is giving error ptor is not defined. How to resolve ptor is not defined error? Thanks   Hi, If you are still
package
package  by what name we can save a java file that contain a package {i.e package p;} and several public classes {i.e public class abc} but not a main method
User Defined Exception
User Defined Exception     ....     How to Handle and create User-defined Exception The keywords used... of the exception Understand User-Defined Exceptions with Example- In the given below
User Defined Exception
User Defined Exception     ....     How to Handle and create User-defined Exception The keywords used... of the exception Understand User-Defined Exceptions with Example- In the given below
package
package  hello, What is a package?   hello,ADS_TO_REPLACE_1 To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability
package
can allow types in one package to have unrestricted access to one another, still restricting the access for the types outside the package
package
package  Smith has created a package named ApplianceDetails that contains the Appliance class.Now he wants to create a class named NewAppliance that stores the details of the newly launched appliances.He uses the following syntax
package
package  Smith has created a package named ApplianceDetails that contains the Appliance class.Now he wants to create a class named NewAppliance that stores the details of the newly launched appliances.He uses the following syntax
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
Excel User Define Error Message
Excel User Define Error Message In this section, you will learn , while cell value validation,  how to show user defined error message using Apache POI...); dataValidation.createErrorBox("Invalid Data", "User Defined Msg->
Servlet Problem proceed - JSP-Servlet
Servlet Problem proceed  Thank you fro your reply. But I couldnt find any serious error.Please see this. User is the package classes/User... servlets mapping is correct. If your package name is User, if you were any
User Define Alert Example
User Define Alert Example       Creating a user defined alert message, In the given example we have created a image that can be fill with some colors and text
Java package
"Date" (user defined) in our program, its name would crash with the Date class of java.util package. To avoid this problem, we can use... are usually defined using a hierarchical naming pattern in which the Package name
NameError: name 'SparkConf' is not defined
NameError: name 'SparkConf' is not defined  Hi, What is solution of the error: NameError: name 'SparkConf' is not defined Thanks   Hi, You should import following line: from pyspark import SparkConf, SparkContext

Ads