Skip to the content
onlineexamguide
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login

classes in java and Objects Interview MCQ Questions and Answers

classes in java

Study and learn Interview MCQ Questions and Answers on classes in java and Objects. Attend job interviews easily with these Multiple Choice Questions.

Java Classes Structure or Syntax Overview Tutorial

A Java program consists of a CLASS with some Code and Data. Code is called Method(s). Data is called Variable(s). Java is an Object-Oriented Language. Let us know more about Java Class Structure and Syntax in this Last Minute Tutorial.

Java Classes Structure and Syntax Overview

A Java Class is like a wrapper or envelope that comprises a number of Methods and Variables. A Java class is like a Blue-Print or Specification-Sheet or Prototype that defines how an Object instantiated out of it (class) to behave and store data.

types of classes in java

A Java Class broadly consists of the following.

  • Variables
  • Methods
  • Constructors

Java Classes Syntax

class CLASSNAME
{
  type1 var_1
  type2 var_2;
  type method1(param1,param2)
  {
    //code
  }
}

Rules For Creating a Class:

  • Each class should contain an Opening Brace “{” and a Closing Brace “}”.
  • and Each method has its own Opening and Closing Braces.
  • Each Java class uses the keyword “class” followed by a valid CLASSNAME.
  • CLASSNAME or simply “Name” can be any valid identifier.
  • and CLASSNAME can start with only a Character Alphabet, Underscore (_) or a Dollar ($) sign.
  • CLASSNAME can not start with a number or digit. But, numbers may come in the middle or end of the NAME.
  • In a .java file, there can only be one “public class“. Other classes defined without specifying “public” access specifier.
  • There is no restriction on the number of methods present in a class.
  • A Java method may or may not return a typed-value.
  • and A Java method can be public, private, protected or default.
  • A Java variable can be public, private, protected or default.
  • The MAIN method is not necessary.
  • Some projects or frameworks do not allow adding a “main” method to the Java program.
  • Some complex Java classes contain “implements” or “extends” keywords next to the CLASSNAME followed by predefined Class-Names. This is part of Inheritance.

Creating a Java Class Object and Using it

A Java object is like a variable of a particular data-type. Here the Object is of the CLASS-type we define. A Class is of no use unless we create Objects. All objects are created at run-time dynamically. Creating an object involves allocating memory to it and returning a reference or handle of the memory location. We create Java objects using a “new” keyword.

A Java Class exists only theoretically or virtually. But an object exists really in memory. A class is comparable to a Structure in a C programming language.

In the above Infographic, we tried to explain what really an Object is. Here, Cupcake Pan is like a prototype. Assume, it has only one mould. It defines what should be the shape of a final Object. Using methods like Kneading, we turned Variables like Ingredients into useful Cupcakes or Objects. Remember that each Object is unique and has its own properties.

An example of Java Class

.A House object “obj” is created using the “new” keyword. The keyword “new” tells the Java Runtime to allocate some memory to the House object and return a reference to “obj“. Now, the object can be accessed using the reference obj.

Each House object has two properties or variables namely width and height. Method getArea() calculates are of the House object and returns it.

public class House
{
  int width, height;
  int getArea()
  {
    return width*height;
  }
  public static void main(String[] args)
  {
    House obj = new House();
    obj.width = 10;
    obj.height= 20;
    int area = obj.getArea();
    System.out.println("Area of the house = " + area);
  }
}
//OUTPUT
//Area of the house = 200

[WpProQuiz 156]

Write a comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Atal Bihari Vajpayee | श्री अटल बिहारी वाजपेयी जीवन परिचय
  • सम्राट अशोक का जीवन परिचय (Emperor Ashoka)
  • Prithviraj Chauhan
  • बाल गंगाधर तिलक
  • स्वामी दयानंद सरस्वती
  • UPPSC Mines Inspector Recruitment 2022 Notification Out
  • AIIMS Delhi JR Vacancy 2022 [194 Post] Notification and Apply Online
  • भीमराव अम्बेडकर
  • डॉक्टर राजेंद्र प्रसाद का जीवन परिचय
  • श्रीनिवास रामानुजन का जीवन परिचय
  • Amnesty International day
  • World Economic Forum
  • UPSSSC VDO Syllabus and Exam Pattern 2022
  • RBI Officer Grade B Recruitment 2022
  • UKMSSB Assistant Professor Recruitment 2022 Apply Now 339 Post

onlineexamguide

onlineexamguide.com is the ultimate guide that will keep you updated about almost every Exam & Interviews . We aim to provide our readers with an informative details that have been occurring in Examination . Here at onlineexamguide.com , we focus on delivering our readers with the latest exam Pattern Mock test

We Provide Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Quick links

  • About us
  • Privacy Policy
  • Instructor Registration
  • Student Registration
  • Java Programming Tests
  • C programming Tests
  • C++ programming Tests
  • Aptitude Tests

Follow us

Free Online Mock Test

  • UPTET PRIMARY Online Test Series
  • Super TET Mock Test in Hindi 2022
  • CTET Mock Test 2022 Paper 1
  • SSC CHSL Online Mock Test
  • SSC MTS Mock Test 2022
  • SSC CGL Mock Test
  • SSC GD Mock Test
  • ccc online test

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Contact us

For any queries

Email us on - admin@onlineexamguide.com

We will response fast as much as we can
Copyright © 2022 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.