2. Accessing Non-Static Members from the Main:
Summary:
In this presentation we will discuss about the ways of accessing nonstatic members and calling non-static functions from the static main
method which is the entry point of any Java class.
Theory:
• Margin of error is the statistic that represents the magnitude of
sampling error associated with the results of a research that used a
sample for representing the entire population.
•Sampling error occurs by chance we cannot avoid this error because
when we select a sample for representing a population the value of the
sample statistic depends on the elements included in the sample.
Therefore, each sample provides different value of sample statistic.
Therefore, the difference between the value of sample statistic and the
exact population parameter is called sampling error or margin of error.
Higher the margin of error lower is the confidence that the research
result is close to the true population parameter and vice versa.
http://www.tutorsonnet.com/java-programming-homework-help.php
Page 1
3. Formula:
In general formula for computing confidence interval for a population
parameter is,
C.I= Sample statistic ± Margin of error
Margin of error depends on the confidence level with which we want to
estimate the population parameter, standard deviation of the sample
(population if given) and the sample size.
Width of a confidence interval is given by,
Width = 2 * margin of error
Margin of error = half the width of the confidence interval =
Width/2
Accordingly formula for computing confidence interval is,
C.I= Sample statistic± (width/2)
Problem:
http://www.tutorsonnet.com/java-programming-homework-help.php
Page 2
4. • Initial entry point of any Java class is a public static method named as
'main'.
• As 'main' is a static method, we cannot call any non-static member
function of a class without creating class object from the 'main' method
body.
•Similarly we cannot access the non-static members of a class without
creating class object from inside the 'main' method.
Solution:
There are two ways to deal with this kind of a problem.
• Make the function or the class member static. Lithe function does not
callaccess the other non-static functionsmembers of the class, then this
is the way we can solve this problem.
• Create an object of a class and use it to call the non-static functions and
to access the non-static members from inside the 'main' method.
http://www.tutorsonnet.com/java-programming-homework-help.php
Page 3
5. Mistake Example:
public class EvenOdd {
{ boolean isEven(int num) {
return (num%2 == 0); }
public static void main(String args[]) {
int num = 23;
// compiler will give error for this line
if(isEven(num)) {
System.out.println(num + " is an even numbed");
}
}
}
http://www.tutorsonnet.com/java-programming-homework-help.php
Page 4
6. Solution 1:
public class EvenOdd {
static boolean isEven(int num) {
return (num%2 == 0);
}
public static void main(String args[]) {
int num = 24;
// compiler will not give error for this line as the function is declared as
static
if(isEven(num)) {
System.out.println(num + " is an even number!");
}
}
}
http://www.tutorsonnet.com/java-programming-homework-help.php
Page 5
7. Solution 2:
public class EvenOdd {
boolean isEven(int num) {
return (num%2 == 0);
}
public static void main(String args[]) {
int num = 24; EvenOdd evenOddObj = new EvenOdd();
// compiler will not give error for this line as we access the function by
creating an object of
// an EvenOdd class.
if(evenOddObj.isEven(num)) {
System.out.println(num + " is an even number!");
}
}
}
http://www.tutorsonnet.com/java-programming-homework-help.php
Page 6
8. For More Details:
Website: http://www.tutorsonnet.com
Mail Us: sendquestions@tutorsonnet.com
Phone: +91 98803 85500
List of Subjects which we Provide Homework Help:
1 Accounting
9 C
17 JavaScript
2 Finance
10 Visual Basic
18 Shell Scripting
3 Statistics
11 C# (C Sharp)
19 Math
4 Economics
12 Matlab Programming
20 Chemistry
5 Operations
13 Database
21 Physics
6 Marketing
14 ER Diagrams
22 Dissertations
7 Java
15 Oracle
23 Case Study
8 C++
16 Microsoft (MS) Access
24 Project Management