Java OOPS Syntax Flashcards
1
Q
Define a method
A
public void greet() {
System.out.println(“Hello, World!”);
}
1
Q
Create a class
A
Public Class NameOfClass {
}
2
Q
Create a main method
A
public class MyClass {
public static void main(String[] args) {
// Code inside the main method
}
}
3
Q
Create an object
A
MyClass myObject = new MyClass();
4
Q
instate a variabe
A
x=5;
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); } }
6
Q
A