You are on page 1of 4

Strings - in Java, a 

string is an object that are designed to represent and hold a


sequence of characters. String literals are enclosed in double-quotes.

class Main {

public static void main(String[] args) {

// create strings

String S1 = "Java String Data type";

// print strings

System.out.println(S1);

OBJECT

An object contains functions and variables that are accessible when instantiated in the main
class.

public class Animal {

void bark() {

System.out.println("Woof-Woof");

class Main {

public static void main(String[] args) {

Animal dog = new Animal();


dog.bark();

Class: - is used to create objects. A class contains a set of properties and methods that are
common and exhibited by all the objects of the class. It contains fields and methods that
represent the behaviour of an object. A class gets invoked by the creation of the respective object.

Enum - An enum has attributes, methods, and constants - that are public, static, and final
(unchangeable – cannot be overridden). An enum cannot be used to create objects and it cannot
extend other classes. But, the enum can implement interfaces.

//declaration of an enum

enum Level {

LOW,

MEDIUM,
HIGH

 Interface:

All the variables and methods declared inside the interface are by default abstract.
The methods don't have a body and just the method declaration only. The interface is
also known as a fully abstract class.

interface Animal {

public void eat();

class Cat implements Animal {

public void eat() {

System.out.println("omnomnom");

public class Program {

public static void main(String[] args) {

Cat c = new Cat();


c.eat();

You might also like