Java OOPS Syntax Flashcards

1
Q

Define a method

A

public void greet() {
System.out.println(“Hello, World!”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

Create a class

A

Public Class NameOfClass {
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a main method

A

public class MyClass {
public static void main(String[] args) {
// Code inside the main method
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create an object

A

MyClass myObject = new MyClass();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

instate a variabe

A

x=5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create a Java class named MyClass that prints out “The value of x is” concatenated with the value of a variable.

A

public class MyClass {
int x; // instance variable

public static void main(String[] args) {
    // Creating an object of the MyClass class
    MyClass myObject = new MyClass();

    // Accessing instance variable and setting its value
    myObject.x = 10;

    // Accessing instance variable and printing its value
    System.out.println("The value of x is: " + myObject.x);
} }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly