All Exams Test series for 1 year @ ₹349 only
Question

Which of the following is/are correct about java programming?

I. All functions in java must be members of some class

II. Member functions are called methods in java

The correct answer is

Both I and II

Understanding Java Programming Fundamentals: Functions and Methods

Let's carefully analyze the given statements about Java programming to determine their correctness.

Analyzing Statement I: All functions in Java must be members of some class

Java is an object-oriented programming language. A fundamental principle of Java is that all executable code resides within classes. Unlike some other languages (like C), you cannot have standalone functions or procedures outside of a class definition. When you write code that performs an action or calculation, it must be defined as part of a class. These pieces of code within a class that perform specific tasks are commonly known as functions in a general programming sense.

Therefore, in Java, every function (or block of code that performs a specific operation) is associated with and defined within a class, making it a member of that class. This statement accurately reflects a core aspect of Java's structure.

Conclusion for Statement I: This statement is correct.

Analyzing Statement II: Member functions are called methods in java

In object-oriented programming terminology, a "member function" is a function that is defined within a class and operates on the data members (attributes or fields) of that class. In Java, the term used for these member functions is "method". Whether it's a function that operates on object instances (instance methods) or functions associated with the class itself (static methods), Java consistently refers to them as methods.

For example, if you have a class `Car`, functions like `startEngine()`, `accelerate()`, or `stop()` defined within this class are all called methods of the `Car` class.

Conclusion for Statement II: This statement is correct.

Conclusion

Based on the analysis of both statements, we find that Statement I (All functions in Java must be members of some class) and Statement II (Member functions are called methods in java) are both correct in the context of Java programming.

Let's summarize our findings:

  • Statement I confirms the class-based nature of Java code organization.
  • Statement II confirms the specific terminology ("method") used in Java for member functions.

Revision Table: Java Programming Concepts

Concept Description in Java
Function (General Term) A block of code performing a task. In Java, these exist only within classes.
Member Function A function defined within a class.
Method The specific term used in Java for a member function.
Class A blueprint for creating objects, containing data (fields) and behavior (methods).

Additional Information: Classes, Objects, and Methods in Java

Java is built around the concepts of classes and objects. A class is like a template, and an object is an instance created from that template. Methods define the actions or operations that can be performed by an object of a class, or by the class itself (in the case of static methods). For example, in a `Dog` class, you might have methods like `bark()`, `fetch()`, or `sleep()`. When you create a specific `Dog` object, say `myDog`, you can call these methods on that object, like `myDog.bark()`. Even the entry point of a Java program, the `main` function, is defined as a `static` method within a class (`public static void main(String[] args)`), illustrating that all executable code lives inside classes as methods.

Was this answer helpful?

Important Questions from Java

  1. What is the output of the following java code?

    int m = 1000;

    int k = 3000;

    while (+ + m < – – k);

    System.out.println(m);

  2. Which of the following statements is/are correct regarding the programming of JAVA?

    I. A class that is marked as final cannot be overwritten.

    II. A method that is marked as final cannot be overridden.

  3. What is the function of javap command?

  4. Java Virtual Machine (JVM) is used to execute architectural neutral byte code. Which of the following is needed by the JVM for execution of Java code?

  5. Match List I with List II:

    List IList II
    (A)Localization(I)Encapsulation
    (B)Packaging or binding of a collection of items(II)Abstraction
    (C)Mechanism that enables designer to focus on essential details of a program component.(III)Characteristic of software that indicates the manner in which information is concentrated in program
    (D)Information hiding(IV)Suppressing the operational details of a program component

    Choose the correct answer from the options given below:

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App